在 Debian 上“调 K8s 网络”通常涉及 操作系统网络参数、CNI 插件、路由/防火墙、DNS 和服务网络 几个方面。下面按“从底层到上层”的方式给你一套实用排查与调优思路,适用于 Debian 11/12 + kubeadm 常见场景。
常见组合:
先确认:
kubectl get pods -n kube-system
kubectl get nodes -o wide
ip route
Debian 常带:
firewalld(较少)ufwsystemd-networkd vs NetworkManager建议:
systemctl stop ufw
systemctl disable ufw
确保 NetworkManager 不接管 CNI 接口(Calico/Cilium 很敏感):
# /etc/NetworkManager/conf.d/calico.conf
[keyfile]
unmanaged-devices=interface-name:cali*;interface-name:cilium*;interface-name:flannel*
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
EOF
sysctl --system
modprobe br_netfilter
modprobe overlay
kubectl run test --image=busybox -it --rm -- sh
ping <其他Pod IP>
检查:
ip a
ip route
iptables -t nat -L -n
Calico 示例
kubectl get pods -n kube-system | grep calico
calicoctl node status
常见原因:
Debian 本地检查:
iptables -L -n -v
nft list ruleset
kubectl get svc
curl <ClusterIP>:<port>
检查 kube-proxy 模式:
kubectl get configmap -n kube-system kube-proxy -o yaml
iptables(稳定)ipvs(性能更好,但需加载模块)IPVS:
modprobe ip_vs
modprobe ip_vs_rr
kubectl exec -it <pod> -- nslookup kubernetes.default
检查:
kubectl get pods -n kube-system | grep coredns
cat /etc/resolv.conf
Debian 注意:
/etc/resolv.conf 被 systemd-resolved 改坏systemctl stop systemd-resolved
systemctl disable systemd-resolved
→ kube-proxy / iptables / ipvs
→ CNI / 路由 / 防火墙
→ CoreDNS / resolv.conf
→ MTU(VXLAN 常见)
ip link show
Calico 可设 MTU=1400~1450
apt install -y tcpdump iproute2 curl dnsutils
示例:
tcpdump -i any port 53
你可以告诉我:
我可以直接给你 针对性命令或配置文件。