在 Debian 上部署 Kubernetes(K8s)通常分 7 个阶段、约 20 多个具体步骤。下面给你一个标准生产级部署流程(使用 kubeadm),适合 Debian 11/12。
hostnamectl set-hostname master
cat <<EOF >> /etc/hosts
192.168.1.10 master
192.168.1.11 node1
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 curl gnupg2 software-properties-common
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
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 /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
kubeadm token create --print-join-command
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
| 阶段 | 关键步骤 |
|---|---|
| 系统准备 | 关 swap / 内核参数 |
| 容器运行时 | containerd |
| K8s 组件 | kubeadm / kubelet / kubectl |
| 初始化 | kubeadm init |
| 网络 | CNI(Flannel / Calico) |
| 扩容 | kubeadm join |
如果你只是测试 / 本地学习,我可以给你:
你是 生产环境 还是 学习 / 测试?