kubernetesgoogle-cloud-platformgoogle-kubernetes-enginegcp-load-balancer

How do I path rewrite with ingress on GCP external load balancer?


I have an ingress on GCP that routes requests with prefix /api to a backend service, how do rewrite the path to discard the /api prefix? For example, route a request /api/book to /book on the backend service?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: basic-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: some-ip
    networking.gke.io/managed-certificates: some-cert
    kubernetes.io/ingress.class: "gce"
spec:
  defaultBackend:
    service:
      name: some-web-app
      port:
        number: 80
  rules:
  - http:
      paths:
      - path: /api
        pathType: Prefix
        backend:
          service:
            name: some-api
            port:
              number: 80

Solution

  • GCE ingress doesn't support path rewrites (as well as many other features). If you could use nginx ingress class that would be possible with annotations:

    nginx.ingress.kubernetes.io/rewrite-target:
    

    docs 1 docs 2