How to expose kubernetes web server to port 80

7/1/2020

I have a tornado webserver + nginx + DNS. I have moved the webserver to a kubernetes pod and same with nginx.

But i realized that cant expose to port 80 then i kept nginx outside from kubernetes and changed webserver ip by the ip of the pod and works without problems.

The problem is that each time the ssh server restarts the pod's ip changes and i need to manually change the ip on nginx conf.

How can i or keep pod's ip between reloads or expose nginx on a pod to outside?

-- Jaume Garcia Sanchez
ip
kubernetes
nginx

1 Answer

7/1/2020

Use a load balancer between DNS and nginx ingress controller. The load balancer can accept traffic on port 80 and forward to nodeport on which nginx ingress controller is exposed.

Alternatively use the nginx ingress controller and run it with hostNetwork: true in deployment pod spec to run nginx ingress controller directly on port 80 in host's network namespace. Then configure DNS to forward traffic to nodeip:80

Create a cluster IP type kubernetes service and an ingress resource to access pod exposed via nginx. Nginx ingress controller will forward traffic to POD IPs directly. There is no change needed anywhere in this setup in case pod IP changes because nginx ingress controller watches for any change in POD IP and updates the nginx.conf accordingly.

-- Arghya Sadhu
Source: StackOverflow