Running nginx container in kubernetes pod which has python app running using gunicorn

10/16/2018

I have a container which runs a chatbot using python, exposed port 5000 where the bot is running. Now when i deploy this container on kubernetes, I have few questions

  • Do i need to run nginx container in the pod where my app container is running ? If yes why do i need to ? since kubernetes does load balancing
  • If i run nginx container on port 80, do I need to run my app container also on 80 or (can i use a different port like 5000)
  • what role does gunicorn play here ?

I am a little confused because most of the examples i see online everyone pretty much have nginx container in their pods along with the app containers

-- anudeep dhondhe
docker
gunicorn
kubernetes
nginx

1 Answer

10/16/2018

As you mentioned Kubernetes can handle its own load balancing, so the answer to your first question is no, you don't need to run nginx especially in the pod where your application is. Typically, services and pods have IPs that are routable by the cluster network and all traffic which ends at an edge router will be dropped. So in Kubernetes there is a collection of rules that allows inbound connections to reach a cluster services. Which we call Ingress:

An API object that manages external access to the services in a cluster, typically HTTP.

Confusing part is that Ingress on it's own does not do much. You will have to create an Ingress controller which is a daemon deployed as a Pod. Its job is to read the Ingress Resource information and to process that accordingly. Actually any system capable of reverse proxying can be ingress controller. You can read more about Ingress and Ingress controller in practical approach in this article. Also I do not know about your environment so please remember that you should use type LoadBalancer if you are on the Cloud and type NodePort if in bare-metal environment.

Going to your second question you can run your application on any port you want, just remember to adjust that port in all other configuration files.

About ports and how to expose services you should check the sources in documentation on how the Kubernetes model works in comparison to containers model. You can find a an instructive article here.

Unfortunately I do not have experience with gunicorn so I won't be able to tell you what role does it play in here. Hope this helps.

-- aurelius
Source: StackOverflow