0
votes

I am having trouble understanding how ports work when using kubernetes. There are three ports in question

  1. Port that my app is listening on inside the docker container
  2. Port mentioned in kubernetes config file as containerPort
  3. LoadBalancer port when the deployment is exposed as a service

What is the relationship between the above three ports? In my current setup I mention EXPOSE 8000 in my Dockerfile and containerPort: 8000 in kubernetes config file. My app is listening on port 8000 inside the docker container. When I expose this deployment using kubectl expose deployment myapp --type="LoadBalancer", it results in the following service -

$ kubectl get service
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
myapp        10.59.248.232   <some-ip>     8000:32417/TCP   16s

But my curl fails as shown below -

$ curl http://<some-ip>:8000/status/ -i
curl: (52) Empty reply from server

Can someone please explain me how the above three ports work together and what should be their values for successful 'exposure' of my app?

1
Just for reference. I refer these slides pretty often. slideshare.net/CJCullen/kubernetes-networking-55835829. Slide helps to understand core of docker networking and kubernetes networking.Sanket Sudake

1 Answers

0
votes

The issue was with my Django server and not Kubernetes or docker. I was starting my server with python manage.py runserver instead of python manage.py runserver 0.0.0.0:8080 which was causing it to return empty responses as the requests were not coming from localhost.