This topic describes how to perform URL rewrite for Kubernetes ingress resources.

About Support for URL Rewrite for Ingress Resources

Tanzu Kubernetes Grid Integrated Edition with NSX-T supports ingress URL path rewrite using NSX-T v2.5.1+ and NCP v2.5.1+.

All the ingress paths will be rewritten to the provided value. If an ingress has annotation ingress.kubernetes.io/rewrite-target: / and has path /tea, for example, the URI /tea will be rewritten to / before the request is sent to the backend service. Numbered capture groups are supported.

URL Rewrite Example

The following example shows how to implement URL rewrite.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    kubernetes.io/ingress.class: "nsx"
    ncp/use-regex: "True"
    #/tea/cup will be rewritten to /cup before sending request to endpoint
    ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea/(.*)
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee/(.*)
        backend:
          serviceName: coffee-svc
          servicePort: 80
check-circle-line exclamation-circle-line close-line
Scroll to top icon