Docker是kubernetes最常用于运行容器的底层引擎,除了Docker之外还有Podman等;
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
#!/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
#!/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即可。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章