简体   繁体   English

nginx 入口重定向流量

[英]nginx ingress redirect traffic

I deployed nginx ingress controller and randomApp to minikube cluster.我将 nginx 入口 controller 和 randomApp 部署到 minikube 集群。 I have 2 requirements:我有两个要求:

  1. All traffic for "random/.*" should go to the random service “random/.*”的所有流量都应该 go 到随机服务
  2. Other paths should go to the nginx.其他路径应该是 go 到 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.您还需要添加metadata.annotations: kubernetes.io/ingress.class: "nginx"spec.ingressClassName: nginx以允许 ingress.nginx-ingress-controller 发现

Also you shouldn't define default backend service as ingress-nginx-controller.此外,您不应将默认后端服务定义为 ingress-nginx-controller。 Because you will get 503 Service Temporarily Unavailable since nginx-ingress-controller 's nginx.conf didn't be configured for this.因为你会得到503 Service Temporarily Unavailable因为nginx-ingress-controllernginx.conf没有为此配置。 You can give another nginx server's service for it.您可以为它提供另一个 nginx 服务器的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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