Kubernetes Ingress rewrite-target - anyway to preserve the address when rewrite?

12/15/2019

I have a oauth2 service running in pod that require user to send request to

http://[address]/oauth/token?grant_type=client_credentials&scope=[scope]

I have Ingress rule as below, and it seems to me that Ingress is deleting 'oauth' word when it re-writes.

For example, using the Ingress rule below when user submits request to: http://address.com/oauth/token?grant_type=client_credentials&scope=[scope] then the auth-service gets request like this: http://address.com/token?grant_type=client_credentials&scope=[scope]

Is there anyway to fix this?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gateway-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: address.com
    http:
        paths:
        - path: /oauth/*
          backend:
            serviceName: auth-service
            servicePort: 8052
-- hinewwiner
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

12/15/2019

I solved this by just removing rewrite-target annotation.

Also I had to remove /* after /oauth

I hope this helps other people.

-- hinewwiner
Source: StackOverflow