Configuring the NGINX Ingress Controller in Kubernetes
Introduction:
In Kubernetes, Ingress is an API resource that manages external HTTP and HTTPS access to applications running inside a Kubernetes cluster.
Get Rameshk’s stories in your inbox
Join Medium for free to get updates from this writer.
There are several Ingress Controllers available, including:
- NGINX Ingress Controller
- Traefik Ingress Controller
In this article, we will learn about the NGINX Ingress Controller, how it works, and why it is useful for exposing Kubernetes applications.
Advantages of Ingress Controllers Over Kubernetes Services
- Kubernetes Services provide different ways to expose applications, such as
ClusterIP,NodePort, andLoadBalancer. However, Ingress Controllers offer additional capabilities for managing HTTP and HTTPS traffic. - When we expose multiple applications using Kubernetes
LoadBalancerServices in a cloud environment such as AWS, each Service may provision a separate cloud load balancer. - For example, if we have five applications and expose each one using a
LoadBalancerService, we may end up with five cloud load balancers, increasing infrastructure costs. - An Ingress Controller provides centralized HTTP/HTTPS traffic management for Kubernetes applications. Its main advantages are host-based and path-based routing, shared load balancer usage, TLS termination, HTTPS redirection, and advanced traffic controls such as authentication and rate limiting.
How to configure the Nginx-Ingress:
- First we need to deploy the Nginx-Ingress controller
## Nginx Ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.12.0/deploy/static/provider/aws/deploy.yaml- It will create the new “namespace” called “ingress-nginx”
- Now we can create our namespace named as “dev”.
kubectl create namespace dev- Im using the “kubens” utility to switch betweeen the namespaces quickly.
- To switch namespace
kubens dev- Now we need to create the Deployment, secret (for tls certificates) and the Service.
### For Deployment
kubectl create deployment dev-web --image rameshk9059/loading:login --replicas 2
### For TLS secrets
kubectl create secret tls wc-secret --cert fullchain.pem --key privkey.pem
### For Service
kubectl expose deployment dev-web --name dev-svc --port 80#Deployment
# Service
# Secrets
- Now its time to create the Nginx-Ingress
kubectl create ingress nginx-ingress --class nginx --rule 'app.rameshtrain.xyz/=dev-svc:80,tls=wc-secret'Note:
- Ingress-controller can be in any namespace but the secrets, deployments,services,ingress all should be in the same namespace.
- If you want to generate the yaml files from the above mentioned commands just add the below flags
kubectl create deployment dev-web --image rameshk9059/loading:login --replicas 2 --dry-run=client -o yamlIf you have any questions or feedback, please feel free to share them. I will be glad to help.








