我已经按照文档中的说明设置了 Nginx Controller https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/ .我已经使用以下配置设置了 Ingress
入口类
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: nginx
# annotations:
# ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: nginx.org/ingress-controller
入口
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: hn-service-ingress
spec:
ingressClassName: nginx
rules:
- host: hostnameservice.classpath.com
http:
paths:
- path: /test
backend:
serviceName: hostname-service
servicePort: 80
下面是运行 describe
命令时的错误。我得到 All hosts are taken by other resources
kubectl describe ingress hn-service-ingress
Name: hn-service-ingress
Namespace: pradeep
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
hostnameservice.classpath.com
/test hostname-service:80 (100.96.1.12:8111,100.96.1.13:8111,100.96.2.13:8111)
Annotations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Rejected 5s nginx-ingress-controller All hosts are taken by other resources
当我用 cafe
示例检查时,它工作正常。我哪里错了?
注意:我已经配置了 AWS 负载均衡器,并使用 dnslookup 将 /etc/hosts
设置为指向来自 AWS 的 ELB
。
最佳答案
请记住 Nginx
有 3 种类型。 开源 Nginx Ingress Controller
、Nginx Incorporaton
(nginx inc) 和 Nginx Incorporaton Plus
。
正如我在评论中提到的,问题是由使用相同 host
的资源引起的。它叫做Host Collisions .
当多个资源配置同一个主机时,就会发生主机冲突。 Ingress Controller
支持两种处理主机冲突的选项:
- Choosing the Winner
If multiple resources contend for the same host, the Ingress Controller will pick the winner based on the creationTimestamp of the resources: the oldest resource will win. In case there are more than one oldest resources (their creationTimestamp is the same), the Ingress Controller will choose the resource with the lexicographically smallest uid.
- Merging Configuration for the Same Host
It is possible to merge configuration for multiple Ingress resources for the same host. One common use case for this approach is distributing resources across multiple namespaces.
OP 确认,这已通过更改另一个 namespace
中的另一个 Ingress
资源解决。
I was able to resolve this. There was one more Ingress in another namespace
关于kubernetes-ingress - 使用 Nginx Ingress Controller 获取所有主机都被其他资源占用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65540117/