简体   繁体   中英

nginx ingress on kubernetes url routing to host

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM