gpt4 book ai didi

kubectl - Ingress DNS 在容器外不起作用

转载 作者:行者123 更新时间:2023-12-04 13:54:12 27 4
gpt4 key购买 nike

我在 VMware 的 k8s 集群中部署了一个入口。问题是 DNS 在容器内响应:

[root@k8s-cluster ~]# kubectl exec -it -n test ingress-nginx-controller-848bfcb64d-n796z  -- curl localhost/banana -H 'Host: k8s-cluster.lab.buch.int'
banana

但是如果我从集群中尝试:
[root@k8s-cluster ~]# curl localhost/banana
curl: (7) Failed connect to localhost:80; Connection refused
即使我使用 DNS 而不是 localhost 或由 metallb 分配给入口 Controller 的 IP,它也不起作用。
[root@k8s-cluster ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
apple-service ClusterIP 10.97.109.66 <none> 5678/TCP 6d15h
banana-service ClusterIP 10.110.129.29 <none> 5678/TCP 6d15h
ingress-nginx-controller LoadBalancer 10.99.151.233 10.133.2.21 80:31981/TCP,443:30293/TCP 6d15h
ingress-nginx-controller-admission ClusterIP 10.108.116.127 <none> 443/TCP 6d15h
[root@k8s-cluster ~]# kubectl describe ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name: example-ingress
Namespace: test
Address: 10.133.65.148
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
k8s-cluster.lab.buch.int
/apple(/|$)(.*) apple-service:5678 (192.168.86.184:5678)
/banana(/|$)(.*) banana-service:5678 (192.168.76.157:5678)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
Events: <none>
如果我 curl 由metallb分配的外部IP:10.133.2.21
[root@k8s-cluster ~]# curl 10.133.2.21
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
所以,这意味着 nginx 以某种方式工作,但是如果我尝试 curl 10.133.2.21/banana 或 10.133.2.21/apple 它不起作用。
有任何想法吗?

最佳答案

在您的 Ingress配置,您指定了 k8s-cluster.lab.buch.int 主机,因此您可以联系applebanana使用此特定主机名的服务:

curl k8s-cluster.lab.buch.int/apple
curl k8s-cluster.lab.buch.int/banana
解决方案
如果您更改 Ingress主办 * (所有主机)这是默认配置,或从您的 YAML 中删除此字段。
...
rules:
- host: "k8s-cluster.lab.buch.int" ### Here you can change to "*" or remove this field
http:
paths:
- path: "/apple(/|$)(.*)"
backend:
...
通过上述更改,您将能够使用 LoadBalancer 访问您的服务。 IP地址:
$ curl 10.133.2.21/apple
$ curl 10.133.2.21/banana
正如您在 Kubernetes Ingress rules 中所读到的那样文档:

Both the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced Service.


此外, 404 Not Found当您尝试 $ curl 10.133.2.21$ curl k8s-cluster.lab.buch.int是预期行为,因为您没有设置 default-backend

Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)

关于kubectl - Ingress DNS 在容器外不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65562994/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com