Build K8s

以kubernetes1.28、ubuntu22.04为例,搭建k8s集群过程中比较重要的一些点:

文档中提到的注意事项,特别是在kubeadm初始化集群时的ERROR、WARNING,务必都处理掉,否则可能会造成后面执行其它步骤奇怪的失败。

容器运行时(CRI)只要安装containerd.io包即可,包括了containerd、runc、CNI插件。 后执行:

sudo mv /etc/containerd/config.toml /etc/containerd/config.toml.bak
containerd config default | sed 's/SystemdCgroup = false/SystemdCgroup = true/' \
| sed 's/registry.k8s.io\/pause:3.6/registry.aliyuncs.com\/google_containers\/pause:3.9/' | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd
sudo swapoff -a
sed 's/\/swap.img/\#\/swap.img/' /etc/fstab | sudo tee /etc/fstab
kubeadm init --image-repository=registry.aliyuncs.com/google_containers

最后根据提示完成初始化动作。

apt安装containerd.io时已经默认安装CNI插件,但无配置, 排查 CNI 插件相关的错误 提供了一个示例:

cat << EOF | sudo tee /etc/cni/net.d/10-containerd-net.conflist
{
 "cniVersion": "1.0.0",
 "name": "containerd-net",
 "plugins": [
   {
     "type": "bridge",
     "bridge": "cni0",
     "isGateway": true,
     "ipMasq": true,
     "promiscMode": true,
     "ipam": {
       "type": "host-local",
       "ranges": [
         [{
           "subnet": "10.88.0.0/16"
         }],
         [{
           "subnet": "2001:db8:4860::/64"
         }]
       ],
       "routes": [
         { "dst": "0.0.0.0/0" },
         { "dst": "::/0" }
       ]
     }
   },
   {
     "type": "portmap",
     "capabilities": {"portMappings": true},
     "externalSetMarkChain": "KUBE-MARK-MASQ"
   }
 ]
}
EOF
sudo systemctl restart containerd

安装dashboard 方便日常管理 下载 dashboard-deployment.yaml 文件后

sed 's/\/master/\/control-plane/g' dashboard-deployment.yaml | tee dashboard-deployment.yaml
kubectl apply -f dashboard-deployment.yaml

根据需要修改网络,如NodePort服务:

kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard

登录信息参考【安装dashboard】-【访问 Dashboard 用户界面】配置