本集群选择 docker 作为容器运行时。
#在k8s-master上进行操作,为了方便操作,将可执行文件和配置文件进行了分离
#可执行文件放在/opt/TLS/download/docker/bin下
#配置文件放在/opt/TLS/download/docker/cfg下
cd /opt/TLS/download
mkdir -p bin
mv docker/* bin
mv bin docker
mkdir -p docker/cfg
cd /opt/TLS/download/docker/cfg
#创建配置文件
cd /opt/TLS/download/docker/cfg
cat > docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
tee daemon.json << 'EOF'
{
"registry-mirrors": ["https://ung2thfc.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "50m"
},
"storage-driver": "overlay2"
}
EOF
#查看文件目录结构
[root@k8s-master docker]# cd /opt/TLS/download/docker/
[root@k8s-master docker]# tree ./
./
├── bin
│ ├── containerd
│ ├── containerd-shim
│ ├── containerd-shim-runc-v2
│ ├── ctr
│ ├── docker
│ ├── dockerd
│ ├── docker-init
│ ├── docker-proxy
│ └── runc
└── cfg
├── daemon.json
└── docker.service
#创建docker目录
mkdir -p /etc/docker
ssh k8s-node1 "mkdir -p /etc/docker"
#分发docker管理文件
scp /opt/TLS/download/docker/cfg/docker.service /usr/lib/systemd/system/docker.service
scp /opt/TLS/download/docker/cfg/docker.service k8s-node1:/usr/lib/systemd/system/docker.service
#分发docker配置文件
scp /opt/TLS/download/docker/cfg/daemon.json /etc/docker/daemon.json
scp /opt/TLS/download/docker/cfg/daemon.json k8s-node1:/etc/docker/daemon.json
#分发docker可执行文件
scp /opt/TLS/download/docker/bin/* /usr/local/bin
scp /opt/TLS/download/docker/bin/* k8s-node1:/usr/local/bin
#核对docker管理文件
[root@k8s-master docker]# ls -l /usr/lib/systemd/system/docker.service
-rw-r--r-- 1 root root 456 Apr 3 13:17 /usr/lib/systemd/system/docker.service
[root@k8s-master docker]# ssh k8s-node1 "ls -l /usr/lib/systemd/system/docker.service"
-rw-r--r-- 1 root root 456 Apr 3 13:17 /usr/lib/systemd/system/docker.service
#核对docker配置文件
[root@k8s-master docker]# ls -l /etc/docker/daemon.json
-rw-r--r-- 1 root root 219 Apr 3 13:17 /etc/docker/daemon.json
[root@k8s-master docker]# ssh k8s-node1 "ls -l /etc/docker/daemon.json"
-rw-r--r-- 1 root root 219 Apr 3 13:18 /etc/docker/daemon.json
#核对docker可执行文件
[root@k8s-master docker]# ls -l /usr/local/bin/
total 241072
-rwxr-xr-x 1 root root 16659824 Apr 3 12:34 cfssl
-rwxr-xr-x 1 root root 13502544 Apr 3 12:34 cfssl-certinfo
-rwxr-xr-x 1 root root 11029744 Apr 3 12:34 cfssljson
-rwxr-xr-x 1 root root 33908392 Apr 3 13:19 containerd
-rwxr-xr-x 1 root root 6508544 Apr 3 13:19 containerd-shim
-rwxr-xr-x 1 root root 8609792 Apr 3 13:19 containerd-shim-runc-v2
-rwxr-xr-x 1 root root 21131264 Apr 3 13:19 ctr
-rwxr-xr-x 1 root root 52883616 Apr 3 13:19 docker
-rwxr-xr-x 1 root root 64758736 Apr 3 13:19 dockerd
-rwxr-xr-x 1 root root 708616 Apr 3 13:19 docker-init
-rwxr-xr-x 1 root root 2784145 Apr 3 13:19 docker-proxy
-rwxr-xr-x 1 root root 14352296 Apr 3 13:19 runc
[root@k8s-master docker]# ssh k8s-node1 "ls -l /usr/local/bin/"
total 200840
-rwxr-xr-x 1 root root 33908392 Apr 3 13:19 containerd
-rwxr-xr-x 1 root root 6508544 Apr 3 13:19 containerd-shim
-rwxr-xr-x 1 root root 8609792 Apr 3 13:19 containerd-shim-runc-v2
-rwxr-xr-x 1 root root 21131264 Apr 3 13:19 ctr
-rwxr-xr-x 1 root root 52883616 Apr 3 13:19 docker
-rwxr-xr-x 1 root root 64758736 Apr 3 13:19 dockerd
-rwxr-xr-x 1 root root 708616 Apr 3 13:19 docker-init
-rwxr-xr-x 1 root root 2784145 Apr 3 13:19 docker-proxy
-rwxr-xr-x 1 root root 14352296 Apr 3 13:19 runc
#在k8s-master上执行启动命令,设置开启启动,并查看状态
[root@k8s-master docker]# systemctl daemon-reload && systemctl start docker && systemctl enable docker && systemctl status docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-04-03 13:26:46 CST; 72ms ago
Docs: https://docs.docker.com
Main PID: 1466 (dockerd)
CGroup: /system.slice/docker.service
├─1466 /usr/local/bin/dockerd
└─1471 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
Apr 03 13:26:46 k8s-master dockerd[1466]: time="2022-04-03T13:26:46.552291845+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
....
Hint: Some lines were ellipsized, use -l to show in full.
#在k8s-node1上执行启动命令,设置开启启动,并查看状态
[root@k8s-node1 ~]# systemctl daemon-reload && systemctl start docker && systemctl enable docker && systemctl status docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-04-03 13:26:53 CST; 84ms ago
Docs: https://docs.docker.com
Main PID: 1301 (dockerd)
CGroup: /system.slice/docker.service
├─1301 /usr/local/bin/dockerd
└─1307 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
Apr 03 13:26:53 k8s-node1 dockerd[1301]: time="2022-04-03T13:26:53.245105288+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
....
Hint: Some lines were ellipsized, use -l to show in full.