下面给你一个在 Debian 上部署 Kubernetes(k8s)的实用流程,以 kubeadm + containerd 为例(当前最推荐、最通用的方式,适用于 Debian 11/12)。
hostnamectl set-hostname master
# worker 节点
hostnamectl set-hostname node1
cat >> /etc/hosts <<EOF
192.168.1.10 master
192.168.1.11 node1
EOF
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab
cat > /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
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
EOF
sysctl --system
apt update
apt install -y containerd
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
systemctl restart containerd
systemctl enable containerd
apt 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
apt-mark hold kubelet kubeadm kubectl
kubeadm init \
--pod-network-cidr=10.244.0.0/16 \
--cri-socket=unix:///run/containerd/containerd.sock
初始化完成后:
mkdir -p $HOME/.kube
cp -i /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
或 Calico:
kubectl apply -f https://docs.tigera.io/archive/v3.25/manifests/calico.yaml
在 master 初始化输出中会有类似:
kubeadm join 192.168.1.10:6443 --token xxx \
--discovery-token-ca-cert-hash sha256:xxx
在 worker 节点执行即可。
kubectl get nodes
kubectl get pods -A
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
| 问题 | 原因 |
|---|---|
| kubeadm 卡住 | swap 未关 |
| 节点 NotReady | 网络插件未装 |
| cgroup 报错 | containerd 未用 systemd |
如果你愿意,我可以:
你现在的 Debian 版本和节点数量是?