How can frontend communicate with backend if each is on a separate pod and host within kubernetes?

2/13/2019

I am trying to connect a simple application to emulate a frontend container in one pod on one host, which makes a request to another backend container in another pod on another host. This cluster was created by kops on AWS.

The services are created correctly and I am able to reach the default frontend service at the LB url created by frontend service. However, the request /greet which calls backend hangs and eventually times out with 500 error.

I checked logs but it doesn't show anything useful. Am I missing anything that would prevent the pods to communicate?

enter image description here

sample-genericserver "frontend"

@app.route('/greet')
def greet():
    r = requests.get('http://sample-greeter')
    print(r.content)
    return r.content

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int("5000"), debug=True)

//frontend
kubectl run sample-genericserver --image=genericserver --replicas=1 --port=5000
kubectl expose deployment sample-genericserver --port=5000 --type=LoadBalancer

greeter "backend"

@app.route('/')
def hello_world():
    return 'Greetings from BackendService'

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int("8090"), debug=True)


//backend
$ kubectl run sample-greeter --image=greeter --replicas=1 --port=8090
$ kubectl expose deployment sample-greeter --port=8090
-- user1529412
docker
kops
kubernetes

1 Answer

2/14/2019

Thanks to David's answer, I was able to add port number to calling url and backend service was able to respond correctly.

r = requests.get('http://sample-greeter:8090')
-- user1529412
Source: StackOverflow