版本:v1.31
容器运行时:containerd
cni:flannel
系统:Ubuntu22.04
安装部署步骤
安装containerd
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
apt-get install containerd.io -y
修改内核
sudo modprobe br_netfilter
# br_netfilter模块持久化
echo "br_netfilter" | sudo tee /etc/modules-load.d/br_netfilter.conf
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
# 允许 IPv4 转发
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables=1
EOF
sudo sysctl --system
安装 kubelet kubeadm kubectl
# apt-transport-https 可能是一个虚拟包(dummy package);如果是的话,你可以跳过安装这个包
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo 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.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
配置 containerd
containerd config default > /etc/containerd/config.toml
# 打开/etc/containerd/config.toml,配置SystemdCgroup[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]...[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]SystemdCgroup = true
# 配置镜像加速,可能失效。如果失效了 重新找其他可用的代理[plugins."io.containerd.grpc.v1.cri".registry.mirrors][plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.k8s.io"]endpoint = ["k8s.monlor.com"][plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]endpoint = ["dockerproxy.cn"]systemctl restart containerd.service
systemctl status containerd.service
停止交换分区
swapoff -a
# 注释掉 swap 分区
vim /etc/fstab
#/swap.img none swap sw 0 0
部署初始化集群
# apiserver 高可用用来替换后面 SLB 的 VIP 地址,如果不用高可用可以不写
echo '10.204.121.215 cluster-endpoint'>> /etc/hosts
# 初始化集群
kubeadm init --control-plane-endpoint=cluster-endpoint --upload-certs --pod-network-cidr=10.244.0.0/16
# 安装网络插件
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
# 查看集群 pod node状态
kubectl get pod -A
kubectl get node