警告:已拒绝 – 所有主机都已被其他资源占用

huangapple go评论82阅读模式
英文:

Warning: Rejected - All hosts are taken by other resources

问题

我正在尝试设置Nginx Ingress Controller来管理裸机集群中同一主机名上的两个路径。

app1命名空间中,我有以下nginx资源:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app1-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80

app2命名空间中,我有以下nginx资源:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app2-ingress
  namespace: app2
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80

我的app1-service先应用并正常运行,现在当我应用第二个app2-service时,它显示以下警告并无法在浏览器上访问:

Annotations:       <none>
Events:
  Type     Reason    Age   From                      Message
  ----     ------    ----  ----                      -------
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources

我如何配置我的Nginx Ingress资源以连接同一主机名上的多个服务路径?

英文:

I'm trying to setup Nginx-ingress controller to manage two paths on the same hostname in bare metal based cluster.

In the app1 namespace i have below nginx resource:-

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app1-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80

And in the app2 namespace i have below nginx resource:-

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app2-ingress
  namespace: app2
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80

My app1-service applied first and it is running fine, now when i applied the second app2-service it shows below warning and not able to access it on browser.

Annotations:       <none>
Events:
  Type     Reason    Age   From                      Message
  ----     ------    ----  ----                      -------
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources

How do i configure my nginx ingress resource to connect multiple service paths on the same hostname?

答案1

得分: 2

默认的Nginx Ingress控制器不支持具有相同主机名的不同Ingress资源。您可以有一个Ingress资源,其中包含多个路径,但在这种情况下,所有应用程序应该存在于一个命名空间中。就像这样:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app1-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80

目前,标准的Nginx Ingress控制器不支持在不同命名空间之间分割Ingress。

但是,您可以查看由Nginx Inc提供的Nginx Ingress的备用实现。它们支持可合并的Ingress

英文:

Default Nginx Ingress controller doesn't support having different Ingress resources with the same hostname. You can have one Ingress resource that contains multiple paths, but in this case all apps should live in one namespace. Like this:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app1-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80

Splitting ingresses between namespaces is currently not supported by standard Nginx Ingress controller.

You may however take a look at an alternative implementation of Nginx Ingress by Nginx Inc. They have support for Mergeable Ingresses.

huangapple
  • 本文由 发表于 2023年2月18日 10:02:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定