当前位置:   article > 正文

​k8s 1.24 1.25 集群使用docker作为容器

--node-labels=node.kubernetes.io/node=

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

背景

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

查看当前容器运行时

 
 
  1. # 查看指定节点容器运行时
  2. kubectl describe node k8s-node05 | grep Container
  3. Container Runtime Version: containerd://1.6.8
  4. # 查看所有节点容器运行时
  5. kubectl describe node | grep Container
  6. Container Runtime Version: containerd://1.6.8
  7. Container Runtime Version: containerd://1.6.8
  8. Container Runtime Version: containerd://1.6.8
  9. Container Runtime Version: containerd://1.6.8
  10. Container Runtime Version: containerd://1.6.8
  11. Container Runtime Version: containerd://1.6.8
  12. Container Runtime Version: containerd://1.6.8
  13. Container Runtime Version: containerd://1.6.8

安装docker

 
 
  1. # 更新源信息
  2. yum update
  3. # 安装必要软件
  4. yum install -y yum-utils device-mapper-persistent-data lvm2
  5. # 写入docker源信息
  6. sudo yum-config-manager \
  7. --add-repo \
  8. https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
  9. # 更新源信息并进行安装
  10. yum update
  11. yum install docker-ce docker-ce-cli containerd.io
  12. # 配置加速器
  13. sudo mkdir -p /etc/docker
  14. sudo tee /etc/docker/daemon.json <<-'EOF'
  15. {
  16. "registry-mirrors": ["https://ted9wxpi.mirror.aliyuncs.com"],
  17. "exec-opts": ["native.cgroupdriver=systemd"]
  18. }
  19. EOF
  20. sudo systemctl daemon-reload
  21. sudo systemctl restart docker

安装cri-docker

 
 
  1. # 由于1.24以及更高版本不支持docker所以安装cri-docker
  2. # 下载cri-docker
  3. wget https://ghproxy.com/https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.5/cri-dockerd-0.2.5.amd64.tgz
  4. # 解压cri-docker
  5. tar xvf cri-dockerd-0.2.5.amd64.tgz
  6. cp cri-dockerd/cri-dockerd /usr/bin/
  7. # 写入启动配置文件
  8. cat > /usr/lib/systemd/system/cri-docker.service <<EOF
  9. [Unit]
  10. Description=CRI Interface for Docker Application Container Engine
  11. Documentation=https://docs.mirantis.com
  12. After=network-online.target firewalld.service docker.service
  13. Wants=network-online.target
  14. Requires=cri-docker.socket
  15. [Service]
  16. Type=notify
  17. ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7
  18. ExecReload=/bin/kill -s HUP $MAINPID
  19. TimeoutSec=0
  20. RestartSec=2
  21. Restart=always
  22. StartLimitBurst=3
  23. StartLimitInterval=60s
  24. LimitNOFILE=infinity
  25. LimitNPROC=infinity
  26. LimitCORE=infinity
  27. TasksMax=infinity
  28. Delegate=yes
  29. KillMode=process
  30. [Install]
  31. WantedBy=multi-user.target
  32. EOF
  33. # 写入socket配置文件
  34. cat > /usr/lib/systemd/system/cri-docker.socket <<EOF
  35. [Unit]
  36. Description=CRI Docker Socket for the API
  37. PartOf=cri-docker.service
  38. [Socket]
  39. ListenStream=%t/cri-dockerd.sock
  40. SocketMode=0660
  41. SocketUser=root
  42. SocketGroup=docker
  43. [Install]
  44. WantedBy=sockets.target
  45. EOF
  46. # 进行启动cri-docker
  47. systemctl daemon-reload ; systemctl enable cri-docker --now

为kubelet配置容器运行时

  1. # 1.25 版本下 所有k8s节点配置kubelet service
  2. cat > /usr/lib/systemd/system/kubelet.service << EOF
  3. [Unit]
  4. Description=Kubernetes Kubelet
  5. Documentation=https://github.com/kubernetes/kubernetes
  6. After=containerd.service
  7. Requires=containerd.service
  8. [Service]
  9. ExecStart=/usr/local/bin/kubelet \\
  10. --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.kubeconfig \\
  11. --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \\
  12. --config=/etc/kubernetes/kubelet-conf.yml \\
  13. --container-runtime-endpoint=unix:///run/cri-dockerd.sock \\
  14. --node-labels=node.kubernetes.io/node=
  15. [Install]
  16. WantedBy=multi-user.target
  17. EOF
  18. # 1.24 版本下 所有k8s节点配置kubelet service
  19. cat > /usr/lib/systemd/system/kubelet.service << EOF
  20. [Unit]
  21. Description=Kubernetes Kubelet
  22. Documentation=https://github.com/kubernetes/kubernetes
  23. After=containerd.service
  24. Requires=containerd.service
  25. [Service]
  26. ExecStart=/usr/local/bin/kubelet \\
  27. --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.kubeconfig \\
  28. --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \\
  29. --config=/etc/kubernetes/kubelet-conf.yml \\
  30. --container-runtime=remote \\
  31. --runtime-request-timeout=15m \\
  32. --container-runtime-endpoint=unix:///run/cri-dockerd.sock \\
  33. --cgroup-driver=systemd \\
  34. --node-labels=node.kubernetes.io/node= \\
  35. --feature-gates=IPv6DualStack=true
  36. [Install]
  37. WantedBy=multi-user.target
  38. EOF
  39. # 重启
  40. systemctl daemon-reload
  41. systemctl restart kubelet
  42. systemctl enable --now kubelet
验证
 
 
  1. # 查看指定节点容器运行时
  2. kubectl describe node k8s-node05 | grep Container
  3. Container Runtime Version: docker://20.10.17
  4. # 查看所有节点容器运行时
  5. kubectl describe node | grep Container
  6. Container Runtime Version: containerd://1.6.8
  7. Container Runtime Version: containerd://1.6.8
  8. Container Runtime Version: containerd://1.6.8
  9. Container Runtime Version: containerd://1.6.8
  10. Container Runtime Version: containerd://1.6.8
  11. Container Runtime Version: containerd://1.6.8
  12. Container Runtime Version: containerd://1.6.8
  13. Container Runtime Version: docker://20.10.17

关于

https://www.oiox.cn/

https://www.oiox.cn/index.php/start-page.html

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

全网可搜《小陈运维》

文章主要发布于微信公众号

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/477671
推荐阅读
相关标签
  

闽ICP备14008679号