在Debian上部署K8S的網絡配置步驟如下:
基礎設置
/etc/hosts
文件,確保節點間主機名解析正確。sudo swapoff -a
并注釋/etc/fstab
中swap相關行。配置網絡接口
/etc/network/interfaces
文件,設置靜態IP或DHCP(示例為靜態IP配置):auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
```。
安裝容器運行時
overlay
、br_netfilter
):sudo apt install containerd
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
sudo modprobe overlay br_netfilter
```。
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes.conf
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
EOF
sudo sysctl --system
```。
初始化K8S集群
kubeadm init
,指定Pod網絡CIDR(如--pod-network-cidr=10.244.0.0/16
)。/etc/kubernetes/admin.conf
復制到~/.kube/config
。安裝網絡插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
。kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
,并開放防火墻端口(如179、4789)。防火墻配置
sudo ufw allow 6443/tcp
sudo ufw allow 2379/tcp
sudo ufw reload
```。
驗證網絡
kubectl get nodes
,確保為Ready
。注意:具體配置需根據網絡環境調整(如IP段、網關等),生產環境建議使用高可用方案并配置DNS。