ingress上添加具有相同主机的多个Ingress

ingress上添加具有相同主机的多个Ingress

本文介绍了无法在Nginx-ingress上添加具有相同主机的多个Ingress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加应该共享同一主机的多个Ingress.一个Ingress应该处理对www.example.de/some的请求,另一个应处理其他所有请求.

I am trying to add multiple Ingresses which should share the same host.One Ingress should handle requests to www.example.de/some and the one all other requests.

以下是Ingress配置的摘要

Here is a snipped with the Ingress configurations

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: some-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: "www.example.de"
    http:
      paths:
      - path: "/some"
        backend:
          serviceName: some-svc
          servicePort: 8585


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: other-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: "www.example.de"
    http:
      paths:
      - backend:
          serviceName: other-svc
          servicePort: 8080

作为入口控制器,我通过Helm安装了nginx-stable/nginx-ingress

As an ingress-controller I installed the nginx-stable/nginx-ingress via Helm

helm install my-ingress nginx-stable/nginx-ingress

尝试从上方创建两个Ingress时,尝试访问www.example.de(在我的/etc/hosts中映射为127.0.0.1)时,只有一个处于工作状态.

When attempting to create the two Ingresses from above only one is working when trying to access www.example.de (this is mapped to 127.0.0.1 in my /etc/hosts).

在nginx-ingress日志中,看到以下警告:

In the nginx-ingress log is see the following warnings:

2020/01/08 09:33:51 [警告] 560#560:0.0.0.0:443上服务器名称"www.example.de"冲突,已忽略

2020/01/08 09:33:51 [warn] 560#560: conflicting server name "www.example.de" on 0.0.0.0:443, ignored

推荐答案

原来我使用了错误的nginx-ingress控制器. nginxinc/kubernetes-ingress 控制器不支持将Ingress规则与同一主机合并(仅通过可合并的入口).

Turns out that I was using the wrong nginx-ingress controller. The nginxinc/kubernetes-ingress controller does not support merging Ingress rules with the same host (only via Mergeable Ingresses).

应该使用 kubernetes/ingress-nginx .在此处.

Instead the kubernetes/ingress-nginx should be used.The differences between these controllers are listed here.

删除旧控制器并使用以下命令安装kubernetes/ingress-nginx即可解决此问题.

Deleting the old controller and installing kubernetes/ingress-nginx instead using the following command fixed the problem.

helm install my-nginx stable/nginx-ingress

请参见 https://kubernetes.github.io/ingress-nginx /deploy/#using-helm

这篇关于无法在Nginx-ingress上添加具有相同主机的多个Ingress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:04