• Centos7 部署 Containerd


            最近工作中需要部署Containerd给kubernetes集群作为运行时容器,特此记录便于日后查阅

    Containerd Github地址:https://containerd.io/downloads/

            Containerd安装我们使用 1.6.4 版本号

    containerd-1.6.4-linux-amd64.tar.gz 只包含containerd
    cri-containerd-cni-1.6.4-linux-amd64.tar.gz 包含containerd以及cri runc等相关工具包,建议下载本包

    1. #下载tar.gz包
    2. #containerd工具包,包含cri runc等
    3. wget https://github.com/containerd/containerd/releases/download/v1.6.4/cri-containerd-cni-1.6.4-linux-amd64.tar.gz
    4. #备用下载地址
    5. wget https://d.frps.cn/file/kubernetes/containerd/cri-containerd-cni-1.6.4-linux-amd64.tar.gz

            也可以选择直接下载我上传的安装包,传送门:

            Kubernetes CRI Containerd 1.6.4 运行时容器安装包下载地址

            工具包文件如下

    1. #cri-containerd-cni会将我们整个containerd相关的依赖都进行下载下来
    2. [root@k8s-01 containerd]# tar zxvf cri-containerd-cni-1.6.4-linux-amd64.tar.gz -C / #我们直接让它给我们对应的目录给替换掉
    3. etc/
    4. etc/systemd/
    5. etc/systemd/system/
    6. etc/systemd/system/containerd.service
    7. etc/crictl.yaml
    8. etc/cni/
    9. etc/cni/net.d/
    10. etc/cni/net.d/10-containerd-net.conflist
    11. usr/
    12. usr/local/
    13. usr/local/sbin/
    14. usr/local/sbin/runc
    15. usr/local/bin/
    16. usr/local/bin/crictl
    17. usr/local/bin/ctd-decoder
    18. usr/local/bin/ctr
    19. usr/local/bin/containerd-shim
    20. usr/local/bin/containerd
    21. usr/local/bin/containerd-shim-runc-v1
    22. usr/local/bin/critest
    23. usr/local/bin/containerd-shim-runc-v2
    24. usr/local/bin/containerd-stress
    25. opt/
    26. opt/containerd/
    27. opt/containerd/cluster/
    28. opt/containerd/cluster/version
    29. opt/containerd/cluster/gce/
    30. opt/containerd/cluster/gce/cni.template
    31. opt/containerd/cluster/gce/env
    32. opt/containerd/cluster/gce/configure.sh
    33. opt/containerd/cluster/gce/cloud-init/
    34. opt/containerd/cluster/gce/cloud-init/node.yaml
    35. opt/containerd/cluster/gce/cloud-init/master.yaml
    36. opt/cni/
    37. opt/cni/bin/
    38. opt/cni/bin/firewall
    39. opt/cni/bin/portmap
    40. opt/cni/bin/host-local
    41. opt/cni/bin/ipvlan
    42. opt/cni/bin/host-device
    43. opt/cni/bin/sbr
    44. opt/cni/bin/vrf
    45. opt/cni/bin/static
    46. opt/cni/bin/tuning
    47. opt/cni/bin/bridge
    48. opt/cni/bin/macvlan
    49. opt/cni/bin/bandwidth
    50. opt/cni/bin/vlan
    51. opt/cni/bin/dhcp
    52. opt/cni/bin/loopback
    53. opt/cni/bin/ptp

    上面的文件都是二进制文件,直接移动到对应的目录并配置好环境变量就可以进行使用了

            如果我们机器上通过yum安装docker了,可以用下面的命令进行卸载

    1. sudo yum remove docker \
    2. docker-client \
    3. docker-client-latest \
    4. docker-common \
    5. docker-latest \
    6. docker-latest-logrotate \
    7. docker-logrotate \
    8. docker-engine

            接下来我们为每台服务器配置Containerd

    1. #创建配置文件目录
    2. [root@k8s-01 ~]# mkdir /etc/containerd -p
    3. #生成默认配置文件
    4. [root@k8s-01 ~]# containerd config default > /etc/containerd/config.toml
    5. #--config,-c可以在启动守护程序时更改此路径
    6. #配置文件的默认路径位于/etc/containerd/config.toml

            替换默认pause镜像地址

            默认情况下k8s.gcr.io无法访问,所以使用我提供的阿里云镜像仓库地址即可

    1. sed -i 's/k8s.gcr.io/registry.cn-beijing.aliyuncs.com\/abcdocker/' /etc/containerd/config.toml
    2. #所有节点更换默认镜像地址
    3. #我这里使用阿里云地址

            配置systemd作为容器的cgroup driver

    sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/' /etc/containerd/config.toml
    

            Containerd官方操作手册

            默认cri-containerd-cni包中会有containerd启动脚本,我们已经解压到对应的目录,可以直接调用启动

    1. [root@k8s-01 ~]# systemctl enable containerd --now
    2. Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /etc/systemd/system/containerd.service.
    3. [root@k8s-01 ~]# systemctl status containerd #查看containerd启动状态
    4. ● containerd.service - containerd container runtime
    5. Loaded: loaded (/etc/systemd/system/containerd.service; enabled; vendor preset: disabled)
    6. Active: active (running) since Thu 2022-05-12 22:59:19 EDT; 3s ago
    7. Docs: https://containerd.io
    8. Process: 30048 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
    9. Main PID: 30050 (containerd)
    10. Memory: 24.5M
    11. CGroup: /system.slice/containerd.service
    12. └─30050 /usr/local/bin/containerd
    13. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.153514446-04:00" level=info msg="Get image filesystem path \"/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs\""
    14. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154085898-04:00" level=info msg="Start subscribing containerd event"
    15. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154137039-04:00" level=info msg="Start recovering state"
    16. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154230615-04:00" level=info msg="Start event monitor"
    17. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154276701-04:00" level=info msg="Start snapshots syncer"
    18. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154299287-04:00" level=info msg="Start cni network conf syncer for default"
    19. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154316094-04:00" level=info msg="Start streaming server"
    20. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154675632-04:00" level=info msg=serving... address=/run/containerd/containerd.sock.ttrpc
    21. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.154755704-04:00" level=info msg=serving... address=/run/containerd/containerd.sock
    22. May 12 22:59:19 web01 containerd[30050]: time="2022-05-12T22:59:19.155220379-04:00" level=info msg="containerd successfully booted in 0.027654s"

             ctr在我们解压包中已经附带了,直接可以使用

    1. [root@k8s-01 ~]# ctr version
    2. Client: #ctr版本号
    3. Version: v1.6.4
    4. Revision: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
    5. Go version: go1.17.9
    6. Server:
    7. Version: v1.6.4 #containerd版本号
    8. Revision: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
    9. UUID: b376d7b6-c97e-4b39-8144-9624ade3ba84
    10. #可以使用下面命令查看containerd版本号
    11. [root@k8s-01 ~]# containerd --version
    12. containerd github.com/containerd/containerd v1.6.4 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16

            指定 kubernetes 使用 containerd 作为运行时容器,首先查看kubelet的service环境变量内容:

    1. $ vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
    2. # Note: This dropin only works with kubeadm and kubelet v1.11+
    3. [Service]
    4. Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
    5. Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
    6. # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
    7. EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
    8. # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
    9. # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
    10. EnvironmentFile=-/etc/sysconfig/kubelet
    11. ExecStart=
    12. ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

             修改 /var/lib/kubelet/kubeadm-flags.env 环境变量文件,指定Containerd,内容如下:

    1. $ /var/lib/kubelet/kubeadm-flags.env
    2. KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7"

            果是首次启动Kubernetes集群,需要通过kubeadm拉起kubelet(不能单独启动kubelet),否则不能生成环境配置文件导致kubelet启动失败

            master拉起方法:

    1. $ kubeadm init --config=init.default.yaml
    2. # 重置 如果有需要
    3. $ kubeadm reset

            slave拉起方法:

    1. $ kubeadm join 10.0.61.12:6443 --token wxf9yd.teut5tqzrl6ddwsu --discovery-token-ca-cert-hash sha256:d94b6a510d55f634996257f2e9ed95caae6153c44cf013ffbc261c03a4f5754a
    2. # 重置 如果有需要
    3. $ kubeadm reset

            指定Harbor镜像仓库,内容如下:

    1. $ vim /etc/containerd/config.toml
    2. version = 2
    3. root = "/var/lib/containerd"
    4. state = "/run/containerd"
    5. [grpc]
    6. address = "/run/containerd/containerd.sock"
    7. uid = 0
    8. gid = 0
    9. max_recv_message_size = 16777216
    10. max_send_message_size = 16777216
    11. [ttrpc]
    12. address = ""
    13. uid = 0
    14. gid = 0
    15. [debug]
    16. address = ""
    17. uid = 0
    18. gid = 0
    19. level = ""
    20. [metrics]
    21. address = ""
    22. grpc_histogram = false
    23. [cgroup]
    24. path = ""
    25. [timeouts]
    26. "io.containerd.timeout.shim.cleanup" = "5s"
    27. "io.containerd.timeout.shim.load" = "5s"
    28. "io.containerd.timeout.shim.shutdown" = "3s"
    29. "io.containerd.timeout.task.state" = "2s"
    30. [plugins]
    31. [plugins."io.containerd.grpc.v1.cri"]
    32. sandbox_image = "registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.5"
    33. [plugins."io.containerd.grpc.v1.cri".cni]
    34. bin_dir = "/opt/cni/bin"
    35. conf_dir = "/etc/cni/net.d"
    36. max_conf_num = 1
    37. conf_template = ""
    38. [plugins."io.containerd.grpc.v1.cri".registry]
    39. [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
    40. [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
    41. endpoint = ["https://hub-mirror.c.163.com/", "https://registry-1.docker.io"]
    42. [plugins."io.containerd.grpc.v1.cri".registry.mirrors."10.0.61.99:30006"]
    43. endpoint = ["http://10.0.61.99:30006"]

            到此 Centos7 部署 Containerd 介绍完成。

  • 相关阅读:
    C++欧几里得算法求最大公约数和最小公倍数
    vue使用WEB自带TTS实现语音文字互转
    分布式与一致性协议之PBFT算法(一)
    Windows7安装SSH客户端的解决方案
    02-React脚手架+Todos项目(组件拆分, State应用, 组件通信+数据校验, nanoid)
    L38.linux命令每日一练 -- 第六章 文件备份与压缩命令 -- zip和unzip
    2022还不知道接口测试的概念的看过来,全是精华
    C语言中,“>>=”;“<<=”;“&=”;“|=”分别代表什么
    【多服务场景化解决方案】智能家居(UrbanHome)
    再谈函数的栈帧
  • 原文地址:https://blog.csdn.net/qq_19734597/article/details/128193692