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

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


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.


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.


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/