k8s 部署步骤整理(containerd)

版本:v1.31

容器运行时:containerd

网络插件:flannel

系统:Ubuntu22.04

安装部署步骤

安装containerd

bash 复制代码
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

修改内核

bash 复制代码
# flannel 需要开启此模块
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

bash 复制代码
# 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

bash 复制代码
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

关闭自带防火墙

bash 复制代码
systemctl stop ufw
systemctl stop apparmor
systemctl disable apparmor
systemctl disable ufw

停止交换分区

bash 复制代码
swapoff -a
# 注释掉 swap 分区
vim /etc/fstab
#/swap.img       none    swap    sw      0       0

部署初始化集群

bash 复制代码
# 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
相关推荐
huosenbulusi5 小时前
helm推送到harbor私有库--http: server gave HTTP response to HTTPS client
云原生·容器·k8s
不会飞的小龙人6 小时前
Docker Compose创建镜像服务
linux·运维·docker·容器·镜像
不会飞的小龙人6 小时前
Docker基础安装与使用
linux·运维·docker·容器
weixin_SAG7 小时前
第3天:阿里巴巴微服务解决方案概览
微服务·云原生·架构
helianying559 小时前
云原生架构下的AI智能编排:ScriptEcho赋能前端开发
前端·人工智能·云原生·架构
元气满满的热码式11 小时前
K8S中Service详解(三)
云原生·容器·kubernetes
染诗11 小时前
docker部署flask项目后,请求时总是报拒绝连接错误
docker·容器·flask
大梦百万秋11 小时前
探索微服务架构:从单体应用到微服务的转变
微服务·云原生·架构
张3蜂13 小时前
docker 部署.netcore应用优势在什么地方?
docker·容器·.netcore