How to setup nginx as reverse proxy for rest microservice in kubernetes?

5/14/2018

I have a rest microservice and would like to setup nginx as a reverse proxy for it. I am little confused about which approach to follow:

  1. Run nginx in each pod where application code is running.
  2. Run nginx in separate pods and redirect http requests to application code running in separate pods.

Can someone explain which one is better

-- madcolonel10
docker
kubernetes
microservices
nginx

3 Answers

5/18/2018

For what do you need the proxy? When it's for exposing the service to the outside world, have a look at Ingress / Ingress Controller: https://kubernetes.io/docs/concepts/services-networking/ingress/

-- slintes
Source: StackOverflow

5/14/2018

In my opinion, running nginx in a separate pod is a better option because that way you can scale up and down application separately from a proxy. Usually, we use one container with proxy and few with API.

-- kamillitw
Source: StackOverflow

5/15/2018

Option 1 will work but it is looks to be inefficient way to do what you have mentioned. Nginx is a highly capable server (footprint/runtime resources) and can easily be able to serve multiple applications from a separate pod. So I think the option 2 is a better option.

Running nginx separately will have following advantages:

  • Efficient (save on resources and money) because a single nginx will be able to serve multiple applications
  • Possibility to use other nginx capabilities in future (e.g. load balancing)
  • Maintainability - only a single pod to maintain, monitor and troubleshoot (e.g. Upgrade rollout, monitoring etc.) and many more

I have had a similar requirement. I used a single nginx on a separate pod to serve multiple (250) application deployments running on different pods. I used proxy_pass directive to get the job done.

-- Nitb
Source: StackOverflow