# step1:安装containerd
$ wget -P /opt https://github.com/containerd/containerd/releases/download/v1.7.17/containerd-1.7.17-linux-amd64.tar.gz
#这个在github下载很慢,因此将文件下载到ansible主机上之后拷贝到所有节点
$ vim copy-containerd.yaml
-hosts: all
gather_facts: no
tasks:-name: Synchronize files to remote host
copy:src: /opt/containerd-1.7.17-linux-amd64.tar.gz
dest: /opt/containerd-1.7.17-linux-amd64.tar.gz
$ ansible-playbook copy-containerd.yaml
$ ansible all -m shell -a "tar xzf /opt/containerd-1.7.17-linux-amd64.tar.gz -C /usr/local/"
#$ ansible all -m shell -a "cp -r /opt/bin/* /usr/local/bin/
$ ansible all -m shell -a "cat > /lib/systemd/system/containerd.service << EOF
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
TasksMax=infinity
OOMScoreAdjust=-999[Install]
WantedBy=multi-user.target
EOF"
10.runc
$ wget -P /opt https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64
$ vim copy-runc.yaml
-hosts: all
gather_facts: no
tasks:-name: Synchronize files to remote host
copy:src: /opt/runc.amd64
dest: /usr/local/bin/runc
mode:"0755"# step3:创建配置文件
$ ansible all -m shell -a "mkdir -p /etc/containerd"
$ ansible all -m shell -a "containerd config default | tee /etc/containerd/config.toml"
# step4:修改底层容器地址,使用代理就不用修改#$ vim modify-container.yaml-hosts: all
gather_facts: no
tasks:-name: Execute bootstrapped shell command on remote host
become:trueshell:|
sed -i 's|SystemdCgroup = false|SystemdCgroup = true|g' /etc/containerd/config.toml
sed -ri -e 's@(.*sandbox_image = ).*@\1\"registry.aliyuncs.com/google_containers/pause:3.9\"@' /etc/containerd/config.toml-name: Reload the systemd daemon
become:truecommand: systemctl daemon-reload
-name: Restart the containerd service
become:truesystemd:name: containerd
state: restarted
11.containerd proxy
$ vim containerd-proxy.yaml
-hosts: all
gather_facts: no
tasks:-name: http-proxy
become:trueshell:|
sed -i '5a Environment=HTTP_PROXY="http://10.10.50.2:7890"' /lib/systemd/system/containerd.service
sed -i '5a Environment=HTTPS_PROXY="http://10.10.50.2:7890"' /lib/systemd/system/containerd.service
sed -i '5a Environment="NO_PROXY=localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local"' /lib/systemd/system/containerd.service-name: Reload the systemd daemon
become:truecommand: systemctl daemon-reload
-name: Restart the containerd service
become:truesystemd:name: containerd
state: restarted
-name: Reboot
reboot: