Overview and What You Will Learn
An Ingress Controller is a reverse proxy that runs in your cluster and routes external HTTP and HTTPS traffic to Services based on hostname and path, so many services share one cloud load balancer and one place to terminate TLS. Without one, every exposed Service needs its own load balancer.
In this lab, you will:
- Deploy the NGINX Ingress Controller with Helm using a production values file
- Route by path and by host to three demo services
- Terminate TLS with cert-manager
- Add rate limiting, security headers and an IP allowlist
- Debug routing problems with kubectl and the controller logs
SecurityThe community
ingress-nginxproject was retired in March 2026 and no longer receives security fixes, and it had serious admission webhook flaws in 2025 (known as IngressNightmare). It remains common in existing clusters and exams, so this guide covers it, but plan a migration for new clusters. Gateway API implementations and vendor-supported NGINX controllers are the usual targets, and theingress2gatewaytool helps convert Ingress resources. Verify the current status before you choose a controller.
Why This Matters in Production
Picture a payments company like Razorpay with dozens of internal services behind one domain. Without Ingress, each service needs its own load balancer IP, its own certificate and its own security rules, which multiplies cost and drift. A single controller gives one entry point, central TLS and uniform policy. It also concentrates risk, because one wrong rule can send payment traffic to the wrong backend or leave an admin service open to the internet.
Core Principles
How Traffic Flows Through the Controller
A request hits the cloud load balancer, reaches an NGINX controller pod, and is routed to a Service by the first matching host and path rule.
one external IP] LB --> NG[NGINX controller pods] NG -->|api host, /v1/payments| P[payments-service] NG -->|api host, /v1/dashboard| D[dashboard-service] NG -->|admin host| A[admin-service
allowlisted] classDef user fill:#475569,color:#FFFFFF classDef edge fill:#F97316,color:#FFFFFF classDef ctrl fill:#326CE5,color:#FFFFFF classDef svc fill:#10B981,color:#FFFFFF class U user class LB edge class NG ctrl class P,D,A svc
The Four Pieces You Must Not Confuse
Kubernetes does not ship with an Ingress Controller, so an Ingress resource does nothing until one is installed.
| Piece | What it is |
|---|---|
| Ingress Controller | The NGINX pods that read rules and proxy traffic |
| Ingress resource | The YAML that defines host and path rules |
| IngressClass | Names which controller handles an Ingress |
| Annotations | Per-Ingress NGINX settings such as timeouts and rate limits |
Backends must be Services in the same namespace as the Ingress. Use pathType: Prefix for /v1/payments and everything under it, and Exact for a single path.
Detailed Step-by-Step Practical Lab
The lab needs a cluster with a LoadBalancer implementation, helm and kubectl, and a domain you control for real certificates. On kind or minikube there is no cloud load balancer, so use kubectl port-forward -n ingress-nginx svc/ingress-nginx-controller 8443:443 and point --resolve at 127.0.0.1.
- Create a values file with production settings: two replicas with a PodDisruptionBudget, resource requests, the client IP preserved, snippet annotations off, and security headers set centrally:
cat > ingress-values.yaml << 'EOF'controller: replicaCount: 2 minAvailable: 1 allowSnippetAnnotations: false resources: requests: cpu: 100m memory: 180Mi limits: memory: 400Mi nodeSelector: kubernetes.io/os: linux service: externalTrafficPolicy: Local addHeaders: X-Frame-Options: DENY X-Content-Type-Options: nosniff Referrer-Policy: strict-origin-when-cross-originEOF- Install the controller. Pin a chart version after checking
helm search repo ingress-nginx --versions, then read the external IP:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginxhelm repo update helm install ingress-nginx ingress-nginx/ingress-nginx \ --namespace ingress-nginx --create-namespace \ -f ingress-values.yaml kubectl get pods -n ingress-nginxkubectl get ingressclass export LB_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx \ -o jsonpath='{.status.loadBalancer.ingress[0].ip}')echo $LB_IP- Deploy three small demo backends. Each one answers with its own name, so you can see where a request landed:
kubectl create namespace ingress-lab for pair in payments-service:4000 dashboard-service:8080 admin-service:9000; do NAME=${pair%%:*} PORT=${pair##*:} kubectl create deployment $NAME -n ingress-lab \ --image=hashicorp/http-echo:1.0 --port=$PORT \ -- /http-echo -text="$NAME" -listen=:$PORT kubectl expose deployment $NAME -n ingress-lab --port=$PORTdone kubectl get pods,svc -n ingress-lab- Create an Ingress with path-based routing, then test it before DNS exists by pinning the hostname to the load balancer IP:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: api-ingress namespace: ingress-lab annotations: nginx.ingress.kubernetes.io/proxy-body-size: "10m" nginx.ingress.kubernetes.io/proxy-connect-timeout: "30" nginx.ingress.kubernetes.io/proxy-read-timeout: "60"spec: ingressClassName: nginx rules: - host: api.devops.in http: paths: - path: /v1/payments pathType: Prefix backend: service: name: payments-service port: number: 4000 - path: /v1/dashboard pathType: Prefix backend: service: name: dashboard-service port: number: 8080kubectl apply -f ingress-basic.yamlkubectl get ingress -n ingress-lab curl --resolve api.devops.in:80:$LB_IP http://api.devops.in/v1/payments # payments-servicecurl --resolve api.devops.in:80:$LB_IP http://api.devops.in/v1/dashboard # dashboard-servicecurl -i --resolve api.devops.in:80:$LB_IP http://api.devops.in/unknown # 404 from NGINX- Install cert-manager and create an issuer. Start with the Let's Encrypt staging server, because production has strict rate limits while you debug. Point a DNS A record for
api.devops.inat$LB_IPfirst, since the HTTP-01 challenge needs it:
helm repo add jetstack https://charts.jetstack.iohelm repo updatehelm install cert-manager jetstack/cert-manager \ --namespace cert-manager --create-namespace \ --set crds.enabled=true kubectl get pods -n cert-managerapiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: letsencrypt-stagingspec: acme: server: https://acme-staging-v02.api.letsencrypt.org/directory # Swap for the production URL when ready email: rahul@devops.in privateKeySecretRef: name: letsencrypt-staging-key solvers: - http01: ingress: ingressClassName: nginxNo public domain? Use a self-signed issuer for the lab instead, and expect browser warnings:
apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: selfsignedspec: selfSigned: {}- Add TLS to the Ingress. cert-manager sees the annotation, requests a certificate, and stores it in the named secret. Use the issuer you created:
kubectl apply -f cluster-issuer.yaml kubectl annotate ingress api-ingress -n ingress-lab \ cert-manager.io/cluster-issuer=letsencrypt-staging --overwrite kubectl patch ingress api-ingress -n ingress-lab --type merge -p \ '{"spec":{"tls":[{"hosts":["api.devops.in"],"secretName":"api-devops-tls"}]}}' kubectl get certificate -n ingress-lab -w # READY turns True in 1 to 2 minutescurl -k --resolve api.devops.in:443:$LB_IP https://api.devops.in/v1/paymentsTipIf a certificate stays
False, follow the chain:kubectl describe certificate, thencertificaterequest,orderandchallenge. The failing ACME step is named in one of them, and it is usually DNS not pointing at the load balancer.
- Add rate limiting. Limits apply per client IP, so they only work if the real client IP reaches NGINX, which
externalTrafficPolicy: Localhelps with. Then prove it by sending a burst:
kubectl annotate ingress api-ingress -n ingress-lab --overwrite \ nginx.ingress.kubernetes.io/limit-rps="5" \ nginx.ingress.kubernetes.io/limit-connections="10" \ nginx.ingress.kubernetes.io/limit-burst-multiplier="2" for i in $(seq 1 60); do curl -sk -o /dev/null -w "%{http_code}\n" \ --resolve api.devops.in:443:$LB_IP https://api.devops.in/v1/paymentsdone | sort | uniq -c # a mix of 200 and 503 once the limit is hit- Add a second host for the admin service, restricted to office IPs. In controller versions before 1.10 the annotation is
whitelist-source-range. Replace the CIDR with your own:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: admin-ingress namespace: ingress-lab annotations: nginx.ingress.kubernetes.io/allowlist-source-range: "10.0.0.0/8,203.0.113.25/32"spec: ingressClassName: nginx rules: - host: admin.devops.in http: paths: - path: / pathType: Prefix backend: service: name: admin-service port: number: 9000kubectl apply -f ingress-admin.yamlcurl -i --resolve admin.devops.in:80:$LB_IP http://admin.devops.in/ # 403 from outside the allowlist- Troubleshoot the way you would in production. Check endpoints first, because an Ingress with no ready endpoints returns 503:
kubectl describe ingress api-ingress -n ingress-labkubectl get endpoints payments-service -n ingress-lab kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx --tail=50kubectl exec -n ingress-nginx deploy/ingress-nginx-controller -- nginx -tkubectl get events -n ingress-nginx --sort-by='.lastTimestamp'- Clean up. Delete the Ingresses before the controller so the load balancer is released cleanly:
kubectl delete namespace ingress-labhelm uninstall cert-manager -n cert-managerhelm uninstall ingress-nginx -n ingress-nginxProduction Best Practices & Common Pitfalls
Common MistakeCreating Ingress resources before a controller exists. The API server accepts them without an error, but nothing routes traffic. Confirm with
kubectl get pods -n ingress-nginxandkubectl get ingressclassfirst.
SecurityKeep
allowSnippetAnnotationsoff. Snippet annotations let anyone who can create an Ingress inject raw NGINX configuration, and they were central to the 2025 vulnerabilities. Set headers through the controller ConfigMap or Helm values instead.
- Run at least two controller replicas with a PodDisruptionBudget. One pod is a single point of failure for all external traffic.
- Set resource requests and limits. A controller without them can be OOM-killed during a spike and drop every route at once.
- Use
externalTrafficPolicy: Local. It preserves the real client IP, which rate limits, allowlists and audit logs depend on. - Always set
ingressClassName. The oldkubernetes.io/ingress.classannotation is deprecated and behaves unpredictably with multiple controllers. - Prefer one Ingress per service or team. Smaller resources are easier to review, roll back and debug than one huge shared file.
- Test with the staging issuer first. Switch to the production Let's Encrypt URL only after the flow works end to end.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
kubectl get ingress -n NS |
List Ingresses and their addresses |
kubectl describe ingress NAME -n NS |
Show rules and backend endpoint status |
kubectl get ingressclass |
List installed controllers |
kubectl get endpoints SVC -n NS |
Check a Service has ready pods |
kubectl get certificate -n NS |
Check TLS certificate status |
kubectl exec -n ingress-nginx deploy/ingress-nginx-controller -- nginx -t |
Validate the generated NGINX config |
| Problem | Likely cause | Fix |
|---|---|---|
| 404 from NGINX | No host or path match | Check the Host header, path and pathType |
| 503 Service Unavailable | Service has no ready endpoints | Check the selector and the readiness probe |
| 502 Bad Gateway | Backend crashed or wrong port | Check the pod logs and the Service targetPort |
| 413 Request Entity Too Large | Body larger than the limit | Raise proxy-body-size |
| 504 Gateway Timeout | Slow backend | Raise proxy-read-timeout or fix the backend |
Certificate stuck False |
DNS or HTTP-01 challenge failing | Describe the Order and Challenge objects |