3

我使用 kubernetes v12,我的系统是 ubuntu 16。

我使用以下命令创建 DNS 资源。

wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/coredns.yaml.sed

wget https://raw.githubusercontent.com/coredns/deployment/master/kubernetes/deploy.sh
bash deploy.sh -i 10.32.0.10 -r "10.32.0.0/24" -s -t coredns.yaml.sed | kubectl apply -f -

创建 coredns 资源后:我检查资源状态。

  1. 检查 coredns 服务
root@master:~# kubectl get svc -n kube-system
NAME           TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
calico-typha   ClusterIP   10.32.0.10   <none>        5473/TCP   13h
  1. 检查代码 DNS pod 端点
root@master:~# kubectl get ep -n kube-system
NAME                      ENDPOINTS   AGE
calico-typha              <none>      13h
kube-controller-manager   <none>      18d
kube-scheduler            <none>      18d
  1. 我的 DNS 配置:
root@master:~# cat /etc/resolv.conf
nameserver 183.60.83.19
nameserver 183.60.82.98
  1. 检查 CoreDNS pod 日志
root@master:~# kubectl get po -n kube-system | grep coredns-7bbd44c489-5thlj
coredns-7bbd44c489-5thlj   1/1     Running   0          13h
root@master:~#
root@master:~# kubectl logs -n kube-system pod/coredns-7bbd44c489-5thlj
.:53
2019-03-16T01:37:14.661Z [INFO] CoreDNS-1.2.6
2019-03-16T01:37:14.661Z [INFO] linux/amd64, go1.11.2, 756749c
CoreDNS-1.2.6
linux/amd64, go1.11.2, 756749c
 [INFO] plugin/reload: Running configuration MD5 = 2e2180a5eeb3ebf92a5100ab081a6381
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:45913->183.60.83.19:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:42500->183.60.82.98:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:48341->183.60.82.98:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:33007->183.60.83.19:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:52968->183.60.82.98:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:48992->183.60.82.98:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:35016->183.60.83.19:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:58058->183.60.82.98:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:51709->183.60.83.19:53: i/o timeout
 [ERROR] plugin/errors: 2 526217177044940556.1623766979909084596. HINFO: unreachable backend: read udp 10.200.0.93:53889->183.60.82.98:53: i/o timeout
root@master:~#

我发现CoreDNS pod ip无法连接到节点 DNS 服务器 ip address

4

3 回答 3

0

您应该检查 calico 防火墙策略,如果它阻止了来自 pod 的 Internet 访问。您需要检查印花布使用哪种模式的另一个想法:ipip / nat out going

于 2019-03-19T17:15:02.200 回答
0

你缺乏kube-dns服务。

为 kube-dns 服务设置 IP 中的输入变量,-i在您的示例中,已分配给 calico-typha,您需要选择不同的 IP。此外,它应该在有效范围内,但如果不在,kubectl 会提示。deploy.sh10.32.0.10

您始终可以通过运行来检查它kubectl cluster-info dump | grep service-cluster-ip-range

于 2019-03-25T13:29:13.697 回答
0

看到这些 coredns 问题后,我认为这是 coredns/dns/resolv.conf 问题。但是只有当我发现我的 pod 似乎都无法访问 Internet 并且我开始考虑不只是涉及 kube-proxy 时,我才找到了解决方案。

我转向 iptables 看看是否有任何东西阻止访问并查看应用的 10.96.0.10 iptables 规则。我没有在我的 iptables (nft) 中找到任何 iptables 规则,但在我的 iptables-legacy (Debian 10) 中找到了一些规则。我责怪 calico 并从头开始我的 kubernetes 集群。

kubeadm reset -f
rm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetes ~/.kube/*
iptables -F && iptables -X
iptables -t raw -F && iptables -t raw -X
iptables -t mangle -F && iptables -t mangle -X
iptables -t nat -F && iptables -t nat -X

iptables-legacy -F && iptables-legacy -X
iptables-legacy -t raw -F && iptables-legacy -t raw -X
iptables-legacy -t mangle -F && iptables-legacy -t mangle -X
iptables-legacy -t nat -F && iptables-legacy -t nat -X

systemctl restart docker

删除并重新启动。

我通过以下方式启动了我的 kube 集群 sudo kubeadm init --config CLUSTER.yaml --upload-certs

检查 iptables 是否在 iptables-legacy 中(我的默认值是 iptables nft)

将印花布拉到本地并添加:

            - name: FELIX_IPTABLESBACKEND
              value: "NFT"

此外,如果您在CLUSTER.yaml更新中使用不同的 podsubnet 集,请在您的 calicoCALICO_IPV4POOL_CIDR文件中适当地使用。

一旦你通过复制正确的 kube 配置让 kubectl 工作

kubectl apply -f calico.yaml

应用更新的文件。再次仔细检查 iptables。然后您应该能够通过原始kubeadm init输出的命令添加您的控制平面和工作节点。

于 2021-09-23T22:09:58.953 回答