madcolonel10
madcolonel10

Reputation: 743

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

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

Upvotes: 3

Views: 974

Answers (2)

Nitb
Nitb

Reputation: 384

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.

Upvotes: 3

kamillitw
kamillitw

Reputation: 472

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.

Upvotes: 6

Related Questions