Skip to content

Ingress with ingress-nginx — installing and configuring the controller

Install ingress-nginx via Helm, configure a real Ingress with TLS, and use annotations for proxy timeouts, body size, rate limiting, and rewrites.

An Ingress is the rule; an Ingress controller is the thing that turns rules into real traffic. The most widely deployed controller is ingress-nginx (the Kubernetes-maintained one, not the commercial NGINX Inc. distribution). This article walks the Helm install, the IngressClass, a working Ingress with TLS, and the annotations you’ll reach for daily — body size, timeouts, rate limiting, and path rewrites — plus the operational nuances that separate a demo from a production controller.

How to verify

After install, three commands describe the controller’s state:

kubectl -n ingress-nginx get deploy,svc,pod
kubectl get ingressclass
kubectl get ingress -A

The controller Deployment should be at full readiness, the Service of type LoadBalancer should have an external IP, and ingressclass should list nginx as the IngressClass name. From a terminal:

curl -kIv https://app.example.com/
echo | openssl s_client -servername app.example.com -connect app.example.com:443 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates

If you see default-backend-404 instead of your app, the Ingress is not selecting the controller — usually a missing ingressClassName or stale kubernetes.io/ingress.class annotation.

What’s happening

ingress-nginx is a pair of components: a controller (Deployment) and a Service in front of it. The controller watches the Kubernetes API for Ingress, Service, and Endpoint changes, generates an nginx.conf, and signals nginx (via nginx -s reload or Lua) to apply it. The Service in front is normally type: LoadBalancer so external traffic reaches nginx; on bare metal, you’d front it with MetalLB or run it as hostNetwork: true on selected nodes.

The IngressClass object is how multiple controllers coexist. An Ingress specifies which controller to use via ingressClassName: nginx. The old kubernetes.io/ingress.class annotation still works but is deprecated; new Ingresses should use the spec field.

Annotations are how you configure per-Ingress behaviour that the spec doesn’t cover: body size limits, proxy timeouts, custom headers, rate limits, basic auth, rewrites. The annotation namespace is nginx.ingress.kubernetes.io/<name>. Cluster-wide defaults live in the controller’s ConfigMap (ingress-nginx/ingress-nginx-controller).

The procedure

  1. Install via Helm. Pin a chart version so upgrades are explicit, and tune the values for your environment.

    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 \
      --version 4.10.0 \
      --set controller.ingressClassResource.default=true \
      --set controller.config.proxy-body-size="50m" \
      --set controller.config.use-forwarded-headers="true" \
      --set controller.config.enable-real-ip="true" \
      --set controller.service.externalTrafficPolicy=Local \
      --set controller.metrics.enabled=true
  2. Make nginx the default IngressClass so Ingress objects without an explicit class still resolve:

    kubectl annotate ingressclass nginx \
      ingressclass.kubernetes.io/is-default-class=true --overwrite
  3. Define a Service for your app (ClusterIP), then write an Ingress that points at it.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web
      annotations:
        nginx.ingress.kubernetes.io/proxy-body-size: "50m"
        nginx.ingress.kubernetes.io/proxy-read-timeout: "60"
        nginx.ingress.kubernetes.io/ssl-redirect: "true"
    spec:
      ingressClassName: nginx
      tls:
        - hosts: [app.example.com]
          secretName: app-example-com-tls
      rules:
        - host: app.example.com
          http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: web
                    port:
                      number: 80
  4. Issue the TLS cert with cert-manager (see /en/knowledge-base/k8s-cert-manager-tls/). The Ingress can reference an issuer by annotation so the Secret is created on demand:

    metadata:
      annotations:
        cert-manager.io/cluster-issuer: letsencrypt-prod
  5. Add rate limiting at the Ingress level when you can’t trust upstream callers. The simplest is requests-per-second per client IP:

    metadata:
      annotations:
        nginx.ingress.kubernetes.io/limit-rps: "20"
        nginx.ingress.kubernetes.io/limit-burst-multiplier: "3"
  6. Rewrite paths for apps that mount at / but live behind /api/v1/:

    metadata:
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
    spec:
      rules:
        - host: app.example.com
          http:
            paths:
              - path: /api(/|$)(.*)
                pathType: ImplementationSpecific
                backend:
                  service:
                    name: api
                    port: { number: 80 }
  7. Reload safely. ingress-nginx watches CRDs and reloads automatically; you don’t nginx -s reload. To verify a config change landed:

    kubectl -n ingress-nginx exec deploy/ingress-nginx-controller -- \
      cat /etc/nginx/nginx.conf | grep -A2 'server_name app.example.com'

Common pitfalls

  • An Ingress without ingressClassName will be ignored if no default class is set — and silently picked up by any controller if multiple defaults exist.
  • proxy-body-size defaults to 1m; large uploads return 413 Request Entity Too Large until you raise it.
  • externalTrafficPolicy: Cluster (default for the controller Service) loses the client IP unless use-proxy-protocol is on AND the upstream LB sends PROXY protocol — set Local for L4 LBs, configure proxy-protocol carefully for L7 LBs.
  • Two Ingresses claiming the same host with overlapping paths will conflict and the controller emits a warning event — kubectl get events -A catches these.
  • Cert renewals via cert-manager don’t restart the controller, but a Secret type change (e.g. Opaque to kubernetes.io/tls) requires Ingress reconciliation; check the tls.crt is current with the openssl command above.

We operate ingress-nginx for clients with chart pinning, per-environment ConfigMap defaults, real-IP correctly configured for the upstream LB, and rate limits matched to the SLO. See /en/services/managed-operations/.