简体   繁体   English

Pod 无法连接到内部 Kubernetes 服务

[英]Pods are unable to connect to internal Kubernetes service

I have issues with CoreDNS on some nodes are in Crashloopback state due to error trying to reach the kubernetes internal service.由于尝试访问 kubernetes 内部服务时出错,我在某些节点上的 CoreDNS 处于 Crashloopback 状态时遇到问题。

This is a new K8s cluster deployed using Kubespray, the network layer is Weave with Kubernetes version 1.12.5 on Openstack.这是一个使用Kubespray部署的新的K8s集群,网络层是Weave with Kubernetes version 1.12.5 on Openstack。 I've already tested the connection to the endpoints and have no issue reaching to 10.2.70.14:6443 for example.我已经测试了与端点的连接,例如,到达 10.2.70.14:6443 没有问题。 But telnet from the pods to 10.233.0.1:443 is failing.但是从 pod 到 10.233.0.1:443 的 telnet 失败了。

Thanks in advance for the help先谢谢您的帮助

kubectl describe svc kubernetes
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.233.0.1
Port:              https  443/TCP
TargetPort:        6443/TCP
Endpoints:         10.2.70.14:6443,10.2.70.18:6443,10.2.70.27:6443 + 2 more...
Session Affinity:  None
Events:            <none>

And from CoreDNS logs:从 CoreDNS 日志中:

E0415 17:47:05.453762       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:311: Failed to list *v1.Service: Get https://10.233.0.1:443/api/v1/services?limit=500&resourceVersion=0: dial tcp 10.233.0.1:443: connect: connection refused
E0415 17:47:05.456909       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:313: Failed to list *v1.Endpoints: Get https://10.233.0.1:443/api/v1/endpoints?limit=500&resourceVersion=0: dial tcp 10.233.0.1:443: connect: connection refused
E0415 17:47:06.453258       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:318: Failed to list *v1.Namespace: Get https://10.233.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0: dial tcp 10.233.0.1:443: connect: connection refused

Also, checking out the logs of kube-proxy from one of the problematic nodes revealed the following errors:此外,从其中一个有问题的节点检查 kube-proxy 的日志显示以下错误:

I0415 19:14:32.162909       1 graceful_termination.go:160] Trying to delete rs: 10.233.0.1:443/TCP/10.2.70.36:6443
I0415 19:14:32.162979       1 graceful_termination.go:171] Not deleting, RS 10.233.0.1:443/TCP/10.2.70.36:6443: 1 ActiveConn, 0 InactiveConn
I0415 19:14:32.162989       1 graceful_termination.go:160] Trying to delete rs: 10.233.0.1:443/TCP/10.2.70.18:6443
I0415 19:14:32.163017       1 graceful_termination.go:171] Not deleting, RS 10.233.0.1:443/TCP/10.2.70.18:6443: 1 ActiveConn, 0 InactiveConn
E0415 19:14:32.215707       1 proxier.go:430] Failed to execute iptables-restore for nat: exit status 1 (iptables-restore: line 7 failed
)

I had exactly the same problem, and it turned out that my kubespray config was wrong.我遇到了完全相同的问题,结果证明我的 kubespray 配置有误。 Especially the nginx ingress setting ingress_nginx_host_network特别是 nginx 入口设置ingress_nginx_host_network

As it turns our you have to set ingress_nginx_host_network: true (defaults to false)事实证明,您必须设置ingress_nginx_host_network: true (默认为 false)

If you do not want to rerun the whole kubespray script, edit the nginx ingress deamon set如果您不想重新运行整个 kubespray 脚本,请编辑 nginx ingress deamon 集

$ kubectl -n ingress-nginx edit ds ingress-nginx-controller

  1. Add --report-node-internal-ip-address to the commandline:--report-node-internal-ip-address添加到命令行:
spec:
  container:
      args:
       - /nginx-ingress-controller
       - --configmap=$(POD_NAMESPACE)/ingress-nginx
       - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
       - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
       - --annotations-prefix=nginx.ingress.kubernetes.io
       - --report-node-internal-ip-address # <- new
  1. Set the following two properties on the same level as eg serviceAccountName: ingress-nginx :在与 eg serviceAccountName: ingress-nginx相同的级别设置以下两个属性:
serviceAccountName: ingress-nginx
hostNetwork: true # <- new
dnsPolicy: ClusterFirstWithHostNet  # <- new

Then save and quit :wq , check the pod status kubectl get pods --all-namespaces .然后保存退出:wq ,查看 pod 状态kubectl get pods --all-namespaces

Source: https://github.com/kubernetes-sigs/kubespray/issues/4357资料来源: https ://github.com/kubernetes-sigs/kubespray/issues/4357

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM