Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of nginx when I have Kubernetes?

As I'm going through Docker/Kubernetes tutorials, I notice a lot of people put nginx into a pod.

Even after reading about nginx, I am not sure what they are using it for. Doesn't Kubernetes serve your app and handle things like load balancing and whatnot?

Isn't something like Node.js a "web server" that can "serve static assets, do caching, and TLS/SSL"?

So with your Node.js app on Kubernetes you have your app being served, static assets, caching especially with things like Redis, and load balancing, etc., why nginx?

like image 449
atkayla Avatar asked Jul 21 '17 16:07

atkayla


People also ask

Why NGINX is use with Kubernetes?

The NGINX Ingress Controller for Kubernetes combines the benefits of using the Kubernetes control plane to manage load‑balancing configuration with the performance, reliability, and advanced features of NGINX and NGINX Plus.

Does Kubernetes replace NGINX?

NGINX Kubernetes Gateway is not replacing NGINX Ingress Controller. Rather, it is an emerging technology based on the alpha release of the Gateway API specification and is intended for evaluation purposes only – it is not for use in production.

Does Kubernetes ingress use NGINX?

The NGINX Ingress Controller for Kubernetes works with the NGINX webserver (as a proxy).

What NGINX used for?

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.


2 Answers

Kubernetes is load balancing the requests to your app. Now it is up to you whether you want to expose your app directly or you want to use a WebServer in front of it.

Putting Nginx in front of it would allow you to have things like access logs, error logs, caching, serving static files etc... There are cases where you may want to have your app exposed directly (this is usually the case when you build applications in GoLang)

So Nginx is not a must inside a pod, but it depends on your architecture design whether you want it or not

like image 168
Tarun Lalwani Avatar answered Oct 03 '22 07:10

Tarun Lalwani


There can be several reasons why people run an instance of Nginx in a Pod. The most common use case is to serve static assets. For this purpose, Apache or lighttpd will play the same role as well. Without seeing the tutorials, I can't shed light on what role Nginx plays .

Since you mentioned "tutorials", I suspect it's just to serve a static page to say "Hey I'm here! You've successfully deployed something that works.".

To answer your question on k8s handling load-balancing - it does. The Service object does Layer-3 (ie. IP layer) load-balancing between associated pods, and the Ingress object does the same but on Layer-7 (eg. HTTP). Such load-balancing is on a cluster-wide basis.

To summarise, the Nginx in tutorials are likely there just to serve static assets, and k8s load-balances cluster-wide.

like image 22
Eugene Chow Avatar answered Oct 03 '22 07:10

Eugene Chow