在 CentOS 上部署 Kubernetes(k8s),网络配置是关键环节。下面从 系统层网络 → 容器网络 → k8s 网络方案 三个层面给你讲清楚,适合生产/测试环境。
systemctl stop firewalld
systemctl disable firewalld
若不想全关,至少放行:
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
modprobe br_netfilter
systemctl enable --now containerd
确认:
crictl info
K8s 网络必须满足:
⚠️ k8s 本身不提供网络实现,需要 CNI 插件。
特点
安装
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
默认 Pod 网段:
192.168.0.0/16
init 时指定:
kubeadm init --pod-network-cidr=192.168.0.0/16
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Pod 网段:
10.244.0.0/16
kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/master/install/kubernetes/quick-install.yaml
kubeadm init \
--pod-network-cidr=192.168.0.0/16 \
--apiserver-advertise-address=192.168.1.10
配置 kubectl:
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
加入节点:
kubeadm join 192.168.1.10:6443 --token xxx --discovery-token-ca-cert-hash xxx
kubectl get pods -n kube-system
journalctl -u kubelet
kubectl get pods -n kube-system
kubectl describe node <node>
CentOS + kubeadm + Calico 是最稳妥组合
如果你告诉我:
我可以给你 精确的命令配置。