关于docker:Kubernetes-124-125-集群使用docker作为容器

40次阅读

共计 4312 个字符,预计需要花费 11 分钟才能阅读完成。

Kubernetes 1.24 1.25 集群应用 docker 作为容器

背景

在新版本 Kubernetes 环境(1.24 以及以上版本)下官网不在反对 docker 作为容器运行时了,若要持续应用 docker 须要对 docker 进行配置一番。须要装置 cri-docker 作为 Kubernetes 容器

查看以后容器运行时

# 查看指定节点容器运行时
kubectl  describe node k8s-node05  | grep Container
  Container Runtime Version:  containerd://1.6.8

# 查看所有节点容器运行时
kubectl  describe node  | grep Container
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8

装置 docker

# 更新源信息
yum update
# 装置必要软件
yum install -y yum-utils   device-mapper-persistent-data   lvm2

# 写入 docker 源信息
sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

# 更新源信息并进行装置
yum update
yum install docker-ce docker-ce-cli containerd.io


# 配置加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://ted9wxpi.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

装置 cri-docker

# 因为 1.24 以及更高版本不反对 docker 所以装置 cri-docker
# 下载 cri-docker 
wget  https://ghproxy.com/https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.5/cri-dockerd-0.2.5.amd64.tgz

# 解压 cri-docker
tar xvf cri-dockerd-0.2.5.amd64.tgz 
cp cri-dockerd/cri-dockerd  /usr/bin/

# 写入启动配置文件
cat >  /usr/lib/systemd/system/cri-docker.service <<EOF
[Unit]
Description=CRI Interface for Docker Application Container Engine
Documentation=https://docs.mirantis.com
After=network-online.target firewalld.service docker.service
Wants=network-online.target
Requires=cri-docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

StartLimitBurst=3

StartLimitInterval=60s

LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

TasksMax=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target
EOF

# 写入 socket 配置文件
cat > /usr/lib/systemd/system/cri-docker.socket <<EOF
[Unit]
Description=CRI Docker Socket for the API
PartOf=cri-docker.service

[Socket]
ListenStream=%t/cri-dockerd.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
EOF

# 进行启动 cri-docker
systemctl daemon-reload ; systemctl enable cri-docker --now

为 kubelet 配置容器运行时

# 1.25 版本下 所有 k8s 节点配置 kubelet service
cat > /usr/lib/systemd/system/kubelet.service << EOF

[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=containerd.service
Requires=containerd.service

[Service]
ExecStart=/usr/local/bin/kubelet \\
    --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.kubeconfig  \\
    --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \\
    --config=/etc/kubernetes/kubelet-conf.yml \\
    --container-runtime-endpoint=unix:///run/cri-dockerd.sock  \\
    --node-labels=node.kubernetes.io/node=

[Install]
WantedBy=multi-user.target
EOF


# 1.24 版本下 所有 k8s 节点配置 kubelet service
cat > /usr/lib/systemd/system/kubelet.service << EOF

[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=containerd.service
Requires=containerd.service

[Service]
ExecStart=/usr/local/bin/kubelet \\
    --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.kubeconfig  \\
    --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \\
    --config=/etc/kubernetes/kubelet-conf.yml \\
    --container-runtime=remote  \\
    --runtime-request-timeout=15m  \\
    --container-runtime-endpoint=unix:///run/cri-dockerd.sock  \\
    --cgroup-driver=systemd \\
    --node-labels=node.kubernetes.io/node= \\
    --feature-gates=IPv6DualStack=true

[Install]
WantedBy=multi-user.target
EOF



# 重启
systemctl daemon-reload
systemctl restart kubelet
systemctl enable --now kubelet

验证

# 查看指定节点容器运行时
kubectl  describe node k8s-node05  | grep Container
  Container Runtime Version:  docker://20.10.17

# 查看所有节点容器运行时
kubectl  describe node  | grep Container
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  containerd://1.6.8
  Container Runtime Version:  docker://20.10.17

对于

https://www.oiox.cn/

https://www.oiox.cn/index.php…

CSDN、GitHub、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、集体博客

全网可搜《小陈运维》

文章次要公布于微信公众号

正文完
 0