what is the difference between / and /* in ingress spec/rules/http/paths/path

6/28/2019

I have the following ingress resource

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kubernetes-demo-ing
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: \"false\"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: test.my-docker-kubernetes-demo.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: my-demo-service
              servicePort: 3000

My app was not getting accessed here test.my-docker-kubernetes-demo.com i was getting too many redirects error

but when i replaced under path from path: /* to path: /, it worked.

But i am not able to find how it fixed the problem, any help in understanding or explaining this would be great.

-- opensource-developer
kubernetes
minikube

3 Answers

7/2/2019

You should check NGINX Ingress Controller - Rewrite.

Starting in Version 0.22.0, ingress definitions using the annotation nginx.ingress.kubernetes.io/rewrite-targetare not backwards compatible with previous versions. In Version 0.22.0 and beyond, any substrings within the request URI that need to be passed to the rewritten path must explicitly be defined in a capture group

Captured groups are saved in numbered placeholders, chronologically, in the form $1, $2 ... $n. These placeholders can be used as parameters in the rewrite-target annotation.

You can check version in a following way:

kubectl exec -it <nginx-ingress-controller-pod-name> -n ingress-nginx -- /nginx-ingress-controller --version

I think your Ingress should look like the following:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kubernetes-demo-ing
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: test.my-docker-kubernetes-demo.com
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: my-demo-service
              servicePort: 3000
-- Crou
Source: StackOverflow

6/28/2019

You can find a short explanation for spec.rules[].http.paths[].path in k8s.io/api/extensions/v1beta1.

-- Shudipta Sharma
Source: StackOverflow

7/2/2019

The meaning of / and /* depends on your ingress implementation, for example there are different ways of selecting a range of paths using the NGINX vs GCE ingress implementations:

path: /foo/.*

path: /*

You can choose the implementation to use by setting the kubernetes.io/ingress.class annotation.

In your case, assuming you're using NGINX, /* isn't interpreted as a glob pattern so only allows connecting literally to /*. Anything else would be sent to the default backend.

-- dippynark
Source: StackOverflow