在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。