在 Debian 上部署 Kubernetes(K8s)常见有 kubeadm(官方推荐)、二进制手动部署、Rancher / K3s 等方式。下面以 Debian 11/12 + kubeadm 为例,给你一套生产可用、最常用的部署流程。
master 192.168.1.10
node1 192.168.1.11
node2 192.168.1.12
swapoff -a
sed -i '/swap/d' /etc/fstab
hostnamectl set-hostname master
cat >> /etc/hosts <<EOF
192.168.1.10 master
192.168.1.11 node1
192.168.1.12 node2
EOF
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 > /etc/containerd/config.toml
编辑:
vim /etc/containerd/config.toml
修改:
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
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
推荐 Flannel(最简单):
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
检查:
kubectl get pods -n kube-system
在 node1 / node2 执行 Master 输出的命令:
kubeadm join 192.168.1.10:6443 \
--token xxx \
--discovery-token-ca-cert-hash sha256:xxx
如果 token 过期:
kubeadm token create --print-join-command
kubectl get nodes
kubectl get pods -A
输出类似:
NAME STATUS ROLES AGE VERSION
master Ready master 5m v1.29.x
node1 Ready <none> 3m v1.29.x
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
| 方案 | 说明 |
|---|---|
| K3s | 轻量 K8s,适合 Debian / 边缘 |
| Rancher | UI 管理 |
| MicroK8s | Ubuntu 系更友好 |
如果你愿意,我可以:
你现在用的是 Debian 几?单机还是多机?