skip to Main Content

i have tomcat backend service running on kubernetes cluster try to rewrite using ingress with path /blob/api/v1/test-backend > /api/v1/test-backend so
the configuration now is running so can hit to xx.somedomain.com/blob/api/v1/test-backend and i want change to xx.somedomain.com/api/v1/test-backend with rewrites

my basic ingress

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-blob
  namespace: blob-test
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
spec:
  tls:
  - hosts:
    - xx.somedomain.com
    secretName: cert-key
  rules:
  - host: xx.somedomain.com
    http:
      paths:
      - path: /blob/
        backend:
          serviceName: blob-service
          servicePort: 8080
      - path: /
        backend:
          serviceName: web-service
          servicePort: 80

and this is yaml for rewrite /blob/

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-blob
  namespace: blob-test
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  tls:
  - hosts:
    - xx.somedomain.com
    secretName: cert-key
  rules:
  - host: xx.somedomain.com
    http:
      paths:
      - path: /blob/api/v1/some-backend
        backend:
          serviceName: blob-service
          servicePort: 8080

when i test with api tester like talend is got 405 error

2

Answers


  1. Try adding annotation like this
    nginx.ingress.kubernetes.io/rewrite-target: "/$1"

    Login or Signup to reply.
  2. Try this

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
      name: rewrite
      namespace: default
    spec:
      rules:
      - host: rewrite.bar.com
        http:
          paths:
          - backend:
              serviceName: http-svc
              servicePort: 80
            path: /something(/|$)(.*)
    

    For example, the ingress definition above will result in the following rewrites:

    rewrite.bar.com/something rewrites to rewrite.bar.com/
    rewrite.bar.com/something/ rewrites to rewrite.bar.com/
    rewrite.bar.com/something/new rewrites to rewrite.bar.com/new
    

    Refer : https://kubernetes.github.io/ingress-nginx/examples/rewrite/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search