以下是在 Debian 上部署 Kubernetes(k8s) 的通用生产级流程,以 kubeadm 方式为例(官方推荐、最常用)。
示例基于 Debian 11/12,适用于 单控制平面或高可用集群。
hostnamectl set-hostname master
# 或 node1 / node2
cat <<EOF >> /etc/hosts
192.168.1.10 master
192.168.1.11 node1
192.168.1.12 node2
EOF
swapoff -a
sed -i '/swap/d' /etc/fstab
cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
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 update
apt install -y containerd
mkdir -p /etc/containerd
containerd config default | tee /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 gpg
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/ /" | \
tee /etc/apt/sources.list.d/kubernetes.list
可替换
v1.29为你需要的版本
apt update
apt install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
kubeadm init \
--pod-network-cidr=10.244.0.0/16 \
--apiserver-advertise-address=192.168.1.10
成功后会输出类似:
kubeadm join 192.168.1.10:6443 --token xxx --discovery-token-ca-cert-hash sha256:xxx
mkdir -p $HOME/.kube
cp /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
或 Flannel:
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
在 worker 节点执行:
kubeadm join 192.168.1.10:6443 \
--token xxx \
--discovery-token-ca-cert-hash sha256:xxx
kubectl get nodes
kubectl get pods -n kube-system
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
| 问题 | 解决 |
|---|---|
| swap 未关闭 | swapoff -a |
| cgroup 不一致 | containerd 开启 systemd cgroup |
| 节点 NotReady | CNI 未安装 |
| token 过期 | kubeadm token create |
✅ Debian 上部署 Kubernetes 推荐流程:
kubeadm init如果你需要:
可以直接告诉我你的 使用场景和节点数量。