nginx ingress on kubernetes url routing to host

12/17/2019

How should my rule look like : if want to support dynamic url mapping to services

/a should map to service service-a
/b should map to service service-b
/cccc should map to service service-cccc

Note : services can be added dynamically

hence afte r say 10 minutes. we now have

/dddd should map to service service-dddd
-- shrw
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

12/17/2019

Basically you keep appending new path to $.spec.rules[x].http.paths, where x is the index of the host which you intend to add path on.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  namespace: my-namespace
  annotations:
    kubernetes.io/ingress.class: "nginx"
    # and other annotations you need..
  #labels:
     # if you need labels
spec:
  rules:
  - host: "your.hostname"
    http:
      paths:
      - path: /a
        backend:
          serviceName: service-a
          servicePort: 443 # say your service runs on 443
      - path: /b
        backend:
          serviceName: service-b
          servicePort: 443 # say your service runs on 443
      - path: /cccc
        backend:
          serviceName: service-cccc
          servicePort: 443 # say your service runs on 443
-- congbaoguier
Source: StackOverflow