12.第十一篇 安装docker引擎
阅读原文时间:2023年07月09日阅读:1

文章转载自:https://mp.weixin.qq.com/s?__biz=MzI1MDgwNzQ1MQ==&mid=2247483838&idx=1&sn=5a13aed5497b6c7144a0ab464f164612&chksm=e9fdd44ade8a5d5c9951d640069e556ef30090b41c9f251a1bfa0fd2964617f72176af957828&scene=178&cur_album_id=1341273083637989377#rd

Docker是kubernetes最常用于运行容器的底层引擎,除了Docker之外还有Podman等;

安装Docker引擎

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &&yum makecache && yum -y install docker-ce

配置镜像加速

#!/bin/bash

cd /data/k8s/work
source /data/k8s/bin/env.sh

# 创建加速配置文件
cat > daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": ["https://hjvrgh7a.mirror.aliyuncs.com"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  }
}
# 添加私有镜像仓库,默认是使用https
# "insecure-registries": ["registry.k8s.vip"],
EOF

# 分发
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh root@${node_ip} "mkdir -p /etc/docker/"
    scp daemon.json root@${node_ip}:/etc/docker/
done

加速配置选项说明

创建启动文件

#!/bin/bash

cd /data/k8s/work
source /data/k8s/bin/env.sh

cp /usr/lib/systemd/system/docker.service /data/k8s/work/

sed -i '/ExecStart/s/\(.*\)/#\1/' /data/k8s/work/docker.service
sed -i '/ExecReload/a ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS -H fd:// --containerd=/run/containerd/containerd.sock' /data/k8s/work/docker.service
sed -i '/ExecReload/a EnvironmentFile=-/run/flannel/docker' /data/k8s/work/docker.service

for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    scp /data/k8s/work/docker.service root@${node_ip}:/usr/lib/systemd/system/
done

启动docker runtime引擎

#!/bin/bash

cd /data/k8s/work
source /data/k8s/bin/env.sh

# 启动
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh root@${node_ip} "systemctl daemon-reload && systemctl enable docker && systemctl restart docker"
done

# 检查
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh root@${node_ip} "systemctl status docker"
done

检查结果:
>>> 192.168.16.104
   Active: active (running) since Sun 2019-12-29 18:05:58 CST; 1 months 1 days ago
>>> 192.168.16.105
   Active: active (running) since Sun 2019-12-29 17:42:35 CST; 1 months 1 days ago
>>> 192.168.16.106
   Active: active (running) since Sun 2019-12-29 17:27:52 CST; 1 months 1 days ago
>>> 192.168.16.107
   Active: active (running) since Sun 2019-12-29 17:49:00 CST; 1 months 1 days ago

flanneld 和 docker 之间网络

#!/bin/bash

cd /data/k8s/work
source /data/k8s/bin/env.sh

for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh root@${node_ip} "/usr/sbin/ip addr show flannel.1 && /usr/sbin/ip addr show docker0"
    echo "\n"
done

检查结果:
>>> 192.168.16.104
3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN
    link/ether aa:ea:b2:e1:88:a5 brd ff:ff:ff:ff:ff:ff
    inet 172.19.120.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
    link/ether 02:42:0d:b7:5a:62 brd ff:ff:ff:ff:ff:ff
    inet 172.19.120.1/21 brd 172.19.127.255 scope global docker0
       valid_lft forever preferred_lft forever

>>> 192.168.16.105
3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN
    link/ether 9a:9d:f2:df:a0:5b brd ff:ff:ff:ff:ff:ff
    inet 172.19.184.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
    link/ether 02:42:c3:44:35:9c brd ff:ff:ff:ff:ff:ff
    inet 172.19.184.1/21 brd 172.19.191.255 scope global docker0
       valid_lft forever preferred_lft forever

>>> 192.168.16.106
3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN
    link/ether ba:f5:d6:06:fb:de brd ff:ff:ff:ff:ff:ff
    inet 172.19.72.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
    link/ether 02:42:e4:56:c1:04 brd ff:ff:ff:ff:ff:ff
    inet 172.19.72.1/21 brd 172.19.79.255 scope global docker0
       valid_lft forever preferred_lft forever

>>> 192.168.16.107
3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN
    link/ether 96:d5:25:87:b0:11 brd ff:ff:ff:ff:ff:ff
    inet 172.19.56.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
    link/ether 02:42:50:85:6e:d9 brd ff:ff:ff:ff:ff:ff
    inet 172.19.56.1/21 brd 172.19.63.255 scope global docker0
       valid_lft forever preferred_lft forever

总结

Docker引擎安装相对简单,但需要与网络插件flannel结合起来使用,只需要简单的配置下启动参数EnvironmentFile即可。

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器