#Nginx #Ingress-Nginx #Kubernetes

#Nginx #Ingress-Nginx #Kubernetes

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:

  • NGINX Load Balancer: Handles external traffic and distributes it efficiently to Kubernetes nodes.
  • Ingress-NGINX Controller: Manages routing within the cluster using Kubernetes ingress rules.

? Why:

  • High Availability
  • Scalability & Flexibility
  • Advanced Traffic Control
  • Security Enhancements

? How:

  1. Deploy Ingress-NGINX in Kubernetes.

#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"
        

  1. Set up NGINX as a reverse proxy load balancer for Ingress-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;
    }
}
        

  1. Define ingress rules to route traffic to your services.

#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
        

要查看或添加评论,请登录

THAN MYINT TUN的更多文章

社区洞察

其他会员也浏览了