在 Debian 上部署 Kubernetes(k8s)时,“配网络”通常包含 三层:
下面按最常用的 Debian + kubeadm方式说明。
编辑:
/etc/network/interfaces
示例:
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
应用:
systemctl restart networking
swapoff -a
sed -i '/swap/d' /etc/fstab
cat <<EOF | tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
apt install -y containerd
containerd config default > /etc/containerd/config.toml
systemctl restart containerd
apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /" > /etc/apt/sources.list.d/kubernetes.list
apt update
apt install -y kubelet kubeadm kubectl
kubeadm init --pod-network-cidr=10.244.0.0/16
10.244.0.0/16是 Flannel 默认网段
mkdir -p $HOME/.kube
cp /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
验证:
kubectl get pods -n kube-flannel
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Calico 默认使用
192.168.0.0/16
在 Master 上获取命令:
kubeadm token create --print-join-command
在 Worker(Debian)上执行:
kubeadm join 192.168.1.10:6443 --token xxx --discovery-token-ca-cert-hash sha256:xxx
kubectl get nodes
kubectl get pods -A
测试 Pod 通信:
kubectl run test --image=busybox -it --rm -- sh
ping 10.244.0.1
✅ 没装 CNI
✅ pod-network-cidr 不匹配
kubectl describe node
通常是 CNI 没起来
Debian 网络 → 关 swap → 装 containerd
→ kubeadm init
→ 装 Flannel/Calico
→ join worker
如果你愿意,我可以:
你现在是 单机测试还是多节点集群?