部署K8S集群(三):子节点部署及加入集群

子节点:

  1. 安装kubelet kubeadm kubectl
hostnamectl set-hostname worker01 --static
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet --now
  1. 安装containerd
    下载地址:https://github.com/containerd/containerd/releases
    找到标签为Latest的包,根据系统类型下载对应的包
#解压
tar Cxzvf /usr/local containerd-1.7.21-linux-amd64.tar.gz
#创建配置文件
mkdir -p /etc/containerd
cat > /etc/containerd/config.toml << EOF
version = 2
[plugins."io.containerd.grpc.v1.cri"]
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"
EOF
#封装成系统服务由systemctl管理启停
cat > /usr/lib/systemd/system/containerd.service << EOF
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF
#加载containerd.service并设置服务自启动
systemctl daemon-reload
systemctl enable --now containerd
systemctl status containerd
  1. 安装runc
    下载地址:https://github.com/opencontainers/runc/releases
    找到标签为Latest的包,根据系统类型下载对应的包
#安装
install -m 755 runc.amd64 /usr/local/sbin/runc
  1. 安装cni-plugin
    下载地址:https://github.com/containernetworking/plugins/releases
    找到标签为Latest的包,根据系统类型下载对应的包
mkdir -p /opt/cni/bin
tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz
导入flannel相关包
ctr -n k8s.io image import flannel_flannel_v0.25.6.tar --digests=true
ctr -n k8s.io image import flannel_flannel-cni-plugin_v1.5.1-flannel2.tar --digests=true
  1. 加入集群
#执行集群初始化时给出的加入集群的命令
kubeadm join 172.17.48.27:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:12dbea4e7f42d9700129fbd26832b19a6dd47615a425eae983391052a65e11af
#检查
kubectl get nodes
##NAME       STATUS   ROLES           AGE   VERSION
##master     Ready    control-plane   29m   v1.28.2
##worker01   Ready    <none>          2m    v1.28.2
posted @ 2024-09-05 15:44  Ar4te  阅读(36)  评论(0编辑  收藏  举报