简体   繁体   中英

nginx ingress redirect traffic

I deployed nginx ingress controller and randomApp to minikube cluster. I have 2 requirements:

  1. All traffic for "random/.*" should go to the random service
  2. Other paths should go to the nginx.

This configuration is correct?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: path-rule-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  defaultBackend:
    service:
      name: ingress-nginx-controller
      port:
        number: 80
  rules:
  - host: random.localdev.me
    http:
      paths:
      - path: /random/(.*)
        backend:
          service:
            name: random
            port:
              number: 8000
        pathType: Prefix     

You also need to add metadata.annotations: kubernetes.io/ingress.class: "nginx" or spec.ingressClassName: nginx to allow nginx-ingress-controller to discover the ingress.

Also you shouldn't define default backend service as ingress-nginx-controller. Because you will get 503 Service Temporarily Unavailable since nginx-ingress-controller 's nginx.conf didn't be configured for this. You can give another nginx server's service for it.

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