← All posts

From ingress-nginx to Gateway API with Envoy Gateway

A practical migration guide for a small cluster: how each ingress-nginx annotation maps to Gateway API resources and Envoy Gateway policies, plus the pitfalls that cost me the most time.

6 min read

On this page

ingress-nginx served my small Kubernetes cluster well for years. With the project in maintenance mode and the Gateway API now stable, I moved everything to Envoy Gateway. The migration was less work than I expected. Most of the time went into a handful of pitfalls, which I describe at the end so you can skip them.

This post assumes a bare-metal-style cluster with a LoadBalancer implementation such as MetalLB, cert-manager for TLS, and Argo CD for GitOps. The examples use documentation addresses (192.0.2.x) and example.com.

The mental model

With ingress-nginx, almost everything is an annotation on an Ingress object. With Gateway API, the responsibilities are split up:

Concerningress-nginxGateway API / Envoy Gateway
Which proxy, which IPcontroller deployment + ServiceGatewayClass + EnvoyProxy
Listeners, TLS certificatestls: block per IngressGateway listeners
Host and path routingIngress rulesHTTPRoute
HTTP → HTTPS redirectssl-redirect annotationRequestRedirect filter
Basic auth / OIDCauth-* annotationsSecurityPolicy
Rate limitslimit-rps annotationBackendTrafficPolicy
Security headersconfiguration-snippetResponseHeaderModifier filter
Real client IPuse-forwarded-headersClientTrafficPolicy

At first this looks like more YAML, and it is. In exchange, each piece has one job, platform settings stay separate from app routing, and there are no free-text snippets for someone to get wrong.

Two gateways: internal and external

I run two separate entry points, each on its own LoadBalancer IP:

  • internal: admin UIs and internal tools, with a wildcard certificate from a private CA
  • external: public websites, with Let's Encrypt certificates per host, and the only one the router forwards ports 80/443 to

Each gets its own GatewayClass and EnvoyProxy, so they are separate Envoy deployments. A mistake on one side cannot take down the other:

yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: eg-external
  namespace: envoy-gateway-system
spec:
  telemetry:
    metrics:
      prometheus: {}
  provider:
    type: Kubernetes
    kubernetes:
      envoyService:
        annotations:
          metallb.universe.tf/loadBalancerIPs: "192.0.2.20"
        patch:
          type: StrategicMerge
          value:
            spec:
              externalTrafficPolicy: Local
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: eg-external
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
  parametersRef:
    group: gateway.envoyproxy.io
    kind: EnvoyProxy
    name: eg-external
    namespace: envoy-gateway-system

externalTrafficPolicy: Local matters more than it looks: it keeps the client's real source IP. Without it, every request seems to come from a node IP, and per-client rate limits stop making sense.

A route, end to end

A typical public site is one HTTPRoute for HTTPS and a shared redirect route for HTTP:

yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: blog
  namespace: blog
spec:
  parentRefs:
    - name: external
      namespace: envoy-gateway-system
      sectionName: https-blog
  hostnames: ["www.example.com"]
  rules:
    - filters:
        - type: ResponseHeaderModifier
          responseHeaderModifier:
            set:
              - name: Strict-Transport-Security
                value: "max-age=31536000; includeSubDomains"
              - name: X-Content-Type-Options
                value: nosniff
              - name: Referrer-Policy
                value: strict-origin-when-cross-origin
      backendRefs:
        - name: blog
          port: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: http-to-https
  namespace: envoy-gateway-system
spec:
  parentRefs:
    - name: external
      sectionName: http
  rules:
    - filters:
        - type: RequestRedirect
          requestRedirect:
            scheme: https
            statusCode: 301

The route lives in the app's namespace. The gateway allows that through allowedRoutes on its listeners, so app teams (or, in my case, app folders in the GitOps repo) own their own routing.

Rate limiting per client IP

Envoy Gateway's global rate limiting needs a small Redis instance. Once that is running, a per-IP limit looks like this:

yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
  name: rl-blog
  namespace: blog
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: blog
  rateLimit:
    type: Global
    global:
      rules:
        - clientSelectors:
            - sourceCIDR: {value: 0.0.0.0/0, type: Distinct}
          limit: {requests: 100, unit: Second}

type: Distinct is the important part. It gives each source IP its own counter, whereas without it all clients share one bucket.

Pick the numbers per type of backend. I first set 20 requests/second for the websites, and image-heavy gallery pages broke right away: a single page view loads 40+ images in parallel, and some of them got 429. Sites now get 100 rps, and APIs keep a strict 5 rps.

If the gateway sits behind another proxy, also tell Envoy how many hops to trust so it picks the right client IP from X-Forwarded-For:

yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
  name: external-xff
  namespace: envoy-gateway-system
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: external
  clientIPDetection:
    xForwardedFor:
      numTrustedHops: 1

Basic auth for admin tools

The old auth-type: basic annotation becomes a SecurityPolicy that points to a secret in htpasswd format:

yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
  name: storage-ui-auth
  namespace: storage
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: storage-ui
  basicAuth:
    users:
      name: storage-ui-htpasswd

The same resource handles OIDC, which I use for tools that should log in through my Git server's identity provider.

Migration strategy

What worked for me:

  1. Run both side by side. Envoy Gateway got new LoadBalancer IPs while ingress-nginx kept the old ones.
  2. Move internal services first. With split DNS, switching a name from the old IP to the new one is a one-line change and easy to roll back.
  3. Test public sites internally by pointing your local DNS at the new external gateway before changing the router's port forwarding.
  4. Switch port forwarding last, then watch the access logs and error rates for a day.
  5. Remove ingress-nginx only when no Ingress objects are left (kubectl get ingress -A is empty).

Pitfalls

  • Argo CD drift. Envoy Gateway writes defaults back into some resources, so Argo CD may show them as permanently OutOfSync. If you add ignoreDifferences with jqPathExpressions, make the expressions null-safe (.spec.foo[]? rather than .spec.foo[]). Otherwise a missing field breaks the comparison and the app stays out of sync.
  • Cross-namespace references need a ReferenceGrant, for example when a gateway in one namespace uses a certificate secret from another, or a route points to a Service in a different namespace.
  • Backends speaking HTTPS. ingress-nginx's backend-protocol: HTTPS has no annotation equivalent. Where possible, run the backend in plain HTTP mode and let the gateway terminate TLS (Argo CD, for example, supports an insecure mode). Otherwise you need a BackendTLSPolicy.
  • NetworkPolicies. If your namespaces default-deny ingress, allow traffic from the Envoy pods' namespace. Remember that unprivileged containers often listen on 8080, not 80.
  • Body size limits. Uploads that worked through nginx may fail with 413. Raise the limit with a ClientTrafficPolicy or BackendTrafficPolicy, depending on where it applies.

Was it worth it?

Yes. The configuration is more explicit, policies are typed and validated instead of being free-form annotations, and internal and external traffic are now really separate. If you still run ingress-nginx in a homelab, the migration is a good weekend project. Start with one internal service and work outwards from there.