[英]Kubernetes ingress nginx route to same path (different service; different port)
I have some simple deployments, pods, services and nginx ingress in Kube.netes.我在 Kube.netes 中有一些简单的部署、pod、服务和 nginx 入口。 I want to use ingress to route to the services (cluster-ip).
我想使用入口路由到服务 (cluster-ip)。
However, there are 2 services for 2 pods with the same path (ie /abc/def).但是,对于具有相同路径(即 /abc/def)的 2 个 pod,有 2 个服务。 After I applied the ingress.yaml file, I got an error message saying "nginx: [emerg] duplicate location "/abc/def/" in /tmp/nginx/nginx-cfg728288520:2893".
在我应用 ingress.yaml 文件后,我收到一条错误消息说“nginx:[emerg] duplicate location “/abc/def/” in /tmp/nginx/nginx-cfg728288520:2893”。
May I know how to let ingress accepts the same paths with different service and different port?我可以知道如何让入口接受具有不同服务和不同端口的相同路径吗?
Here is the ingress.yaml file:这是 ingress.yaml 文件:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
name: ingress-nginx-default
namespace: default
spec:
rules:
- host:
http:
paths:
- path: /abc/def/
pathType: Prefix
backend:
service:
name: service1
port:
number: 8090
- path: /abc/def
backend:
service:
name: service2
port:
number: 8068
pathType: Prefix
ingressClassName: nginx
"nginx: [emerg] duplicate location "/abc/def/" in /tmp/nginx/nginx-cfg728288520:2893". “nginx:[emerg] /tmp/nginx/nginx-cfg728288520:2893 中的重复位置“/abc/def/””。 This error indicates the same host with two same paths which is a duplicate location.
此错误表示具有两个相同路径的同一主机是重复位置。
You can use simple fanout based on path or name based virtual hosting.您可以使用基于路径或基于名称的虚拟主机的简单扇出。 In order to do this you need to have two hosts that need to be mentioned in the ingress.
为此,您需要有两个需要在入口中提及的主机。
based on your example you'd most likely want to have something like foo.bar.com and bar.foo.com
.根据您的示例,您很可能想要
foo.bar.com and bar.foo.com
类的东西。 Here's the example from the Kube.netes docs:这是 Kube.netes 文档中的示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: foo.bar.com
http:
paths: #path_name
- backend:
serviceName: service1
servicePort: 80
- host: bar.foo.com
http:
paths: #path_name
- backend:
serviceName: service2
servicePort: 80
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.