KubeDNS not working inside of pod when its containers are on the same node with kube-dns containers

pod中访问dns出现偶尔超时的问题现在定位原因是:
[问题复现]
若kube-dns的pod与访问dns的pod服务位于同一node节点中时无法通过service的vip访问到该pod
k8s中的issue中也有相同的描述:https://github.com/kubernetes/kubernetes/issues/21613
主要原因是因为:
net.bridge.bridge-nf-call-iptables
net.bridge.bridge-nf-call-ip6tables
参数设置导致无法生产iptables的MASQUERADE规则,是的service的vip无法路由到pod的ip
[解决方法]
sysctl -w net.bridge.bridge-nf-call-iptables=1
sysctl -w net.bridge.bridge-nf-call-ip6tables=1

即使sysctl.conf里设置了,然后sysctl -p生效了。但是机器重启后,sysctl -a查看失效的情

线上经常出现同一台机器上上Pod之间访问不通的问题

线上sysctl.conf已经在机器重启正确配置, 但是docker服务启动时候会reset相关参数

这个过程会体现在/var/log/messages中

目前此问题并没有很完美的办法

初步方案为修改docker service的启动过程,在启动后重新load bridge相关配置:

Step 1:

vim /etc/sysctl.d/bridge.conf

net.bridge.bridge-nf-call-arptables=1

net.bridge.bridge-nf-call-iptables=1

net.bridge.bridge-nf-call-ip6tables=1

Step 2:

sudo sed -i '/ExecStart.*/aExecStartPost=/usr/lib/systemd/systemd-sysctl bridge.conf' /usr/lib/systemd/system/docker.service

原文地址:https://www.cnblogs.com/allenhaozi/p/9553381.html