How to create redirection url

10/4/2019

I would to build following an service deployed to kubernetes to be accessed using an ingress object.

I would like to use https://mylocation.com/myprogram/doc to access the app but only https://mylocation.com/myprogram/doc/ works.

I have created the following entry in my yaml

# -----------------
# Ingress object
# -----------------
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myapp-ingress
  namespace: documentation
  annotations:
    kubernetes.io/ingress.class: nginx
    #Default is 'true'
spec:
  tls:
  - hosts:
    - mylocation.com
  rules:
  - host: mylocation.com
    http:
      paths:
      - backend:
          serviceName: myapp-service
          servicePort: 80
        path: /myapp/doc
      - backend:
          serviceName: myapp-service
          servicePort: 80
        path: /myapp/doc/(.*)

I have created the ingress object kubectl apply -f filename

When I browse http://mylocation.com//myapp/doc, I get HTTP ERROR 404 When I browse http://mylocation.com//myapp/doc/, It works

Can someone help me to get http://mylocation.com//myapp/doc working?

Thanks for your help.

-- Seb HO
kubernetes
nginx-ingress

1 Answer

10/4/2019

Make sure to place appropriate regex

# -----------------
# Ingress object
# -----------------
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myapp-ingress
  namespace: documentation
  annotations:
    kubernetes.io/ingress.class: nginx
    #Default is 'true'
spec:
  tls:
  - hosts:
    - mylocation.com
  rules:
  - host: mylocation.com
    http:
      paths:
      - backend:
          serviceName: myapp-service
          servicePort: 80
        path: /myapp/doc(/|$)(.*)
`
-- Palash Goel
Source: StackOverflow