#Nginx #Ingress-Nginx #Kubernetes
THAN MYINT TUN
Senior Cloud & Systems Engineer | Multi-Cloud (AWS, OCI, Huawei) | Kubernetes | Docker | Storage & Backup | VMware | Linux | Terraform | Automation (Bash, Python)
Let using NGINX Load Balancer with the Ingress-NGINX Controller to optimize traffic flow in our Kubernetes cluster. Here's a quick guide to why and how this combo works wonders:
? What:
? Why:
? How:
领英推荐
#Install the Ingress-NGINX controller using Helm:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace
or
#deploy using YAML:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
or
#download zip file and install by manual
curl -LO https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-4.9.0/ingress-nginx-4.9.0.tgz
helm install ingress-nginx ./ingress-nginx-4.9.0.tgz --namespace ingress-nginx --create-namespace --set controller.ingressClassResource.name="nginx" --set controller.ingressClassResource.controllerValue="k8s.io/nginx"
upstream ingress-nginx {
server <node-ip-1>:<ingress-nginx-port> max_fails=3 fail_timeout=30s;
server <node-ip-2>:<ingress-nginx-port> max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name example.com;
access_log /var/log/ingress-nginx.access.log combined;
error_log /var/log/nginx/ingress-nginx.error.log;
location / {
proxy_pass https://ingress-nginx;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
#Apply the resource: kubectl apply -f my-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80