简体   繁体   English

Kube.netes 入口 nginx 路由到同一路径(不同的服务;不同的端口)

[英]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.

相关问题 NGINX 在同一端口上以不同的路由路径运行多个应用程序 - NGINX Run multiple application on same port with different route path Kubernetes NGINX 入口 controller - 如果查询字符串存在则不同的路由 - Kubernetes NGINX Ingress controller - different route if query string exists 为Kubernetes Traefik Ingress配置每个服务的不同路径重写 - Configure Kubernetes Traefik Ingress with different path rewrites for each service TCP 端口的入口,是否可以以类似的方式使用相同的端口号路由到不同的服务 NGINX 路由 http 端口? - Ingress for TCP ports, is it possible to route to different services using the same port number in a similar way NGINX routes for http ports? Kubernetes Ingress NGINX 重写 - 如何支持不同域的多路径模式 - Kubernetes Ingress NGINX Rewrite - How to Support Multiple Path Patterns for Different Domains Kubernetes nginx 入口路由路径 - Kubernetes nginx ingress route paths 将不同的基本路径路由到相同的代理通过 Nginx - Route different base path to same proxy pass Nginx Kubernetes 入口路径优先级(ingress-nginx) - Kubernetes Ingress path priority (ingress-nginx) GKE 上的 nginx-ingress 无法路由到配置服务的路径 - nginx-ingress on GKE fails to route to path for configured service 使用 Kubernetes 入口资源 (nginx) 在不同路径上的两个 Flask 应用程序 - Two Flask apps on different paths with Kubernetes Ingress resource (nginx)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM