0

I have scoured the Net to try to resolve something that seems to be a common issue, but unfortunately all of the documentation and suggestions have not solve my problem. I hope that you can help me and others with it.

We are migrating from another ingress to nginx-ingress. To validate our installation, I am using httpbin as the backend service.

When I create the following ingress with a path of '/' and send the query, I receive a proper response.

curl -I -k http://abczzz.com/anything

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mikie-ingress
  namespace: mikie
spec:
  ingressClassName: nginx
  rules:
    - host: abczzz.com
      http:
        paths:
          - path: / 
            pathType: Prefix
            backend:
              service:
                name: httpbin-service
                port:
                  number: 8999

What we really need is to be able to redirect to different services off of this single host, so I changed the ingress to the following, but the query always fails with a 404. Basically, I want the /httpbin to disappear and pass the path onto the backend service, httpbin.

curl -I -k http://abczzz.com/httpbin/anything

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mikie-ingress
  namespace: mikie
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/httpbin)$ $1/ redirect;
spec:
  ingressClassName: nginx
  rules:
    - host: abczzz.com
      http:
        paths:
          - path: /httpbin(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: httpbin-service
                port:
                  number: 8999

I'd really appreciate your help to resolve what must be a simple routing issue. Thanks for your time and interest.

A Bit of Help
  • 1,368
  • 19
  • 36

1 Answers1

0

I finally figured things out... Hopefully, the following snippet will help others...

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mikie-ingress
  namespace: mikie
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  ingressClassName: nginx
  rules:
    - host: abczzz.com
      http:
        paths:
          - backend:
              service:
                name: httpbin-service
                port:
                  number: 8999
            path: /httpbin/(.*)
            pathType: Prefix
A Bit of Help
  • 1,368
  • 19
  • 36