目录
- 前言
- 安装 docker
- 创建配置文件
- 修改Docker启动参数
- 启动 docker 服务
前言
正常操作到这里,k8s 的 master 集群已经安装完成,只需要添加node节点就可以了;
但也要把 master 节点都要通过 work 节点的组件,加入到master集群中;
kubernetes work节点运行如下组件:
docker、kubelet、kube-proxy、flanneld、kube-nginx
安装 docker
yum install docker-ce-18.09.6
如果这一步安装有问题,请查看 环境介绍与基础配置 中有个docker的阿里云源
创建配置文件
mkdir -p /etc/docker/
cat > /etc/docker/daemon.json <
修改Docker启动参数
EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS -H fd:// --containerd=/run/containerd/containerd.sock
完整的如下
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
启动 docker 服务
source /opt/k8s/bin/environment.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
检查服务运行状态
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh root@${node_ip} "systemctl status docker|grep Active"
done
检查 docker0 网桥
source /opt/k8s/bin/environment.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"
done
输出结果
>>> 10.0.20.11
6: flannel.1: mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether 2e:40:21:fe:5d:7a brd ff:ff:ff:ff:ff:ff
inet 172.30.224.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
5: docker0: mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:39:44:2b:e5 brd ff:ff:ff:ff:ff:ff
inet 172.30.224.1/21 brd 172.30.231.255 scope global docker0
valid_lft forever preferred_lft forever
>>> 10.0.20.12
6: flannel.1: mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether a6:96:1a:04:30:d8 brd ff:ff:ff:ff:ff:ff
inet 172.30.160.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
5: docker0: mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:68:50:cf:cb brd ff:ff:ff:ff:ff:ff
inet 172.30.160.1/21 brd 172.30.167.255 scope global docker0
valid_lft forever preferred_lft forever
>>> 10.0.20.13
6: flannel.1: mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether 2e:1d:82:42:52:d2 brd ff:ff:ff:ff:ff:ff
inet 172.30.80.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
5: docker0: mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:f2:3f:88:e6 brd ff:ff:ff:ff:ff:ff
inet 172.30.80.1/21 brd 172.30.87.255 scope global docker0
valid_lft forever preferred_lft forever
>>> 10.0.20.14
6: flannel.1: mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether 16:00:ff:7a:69:93 brd ff:ff:ff:ff:ff:ff
inet 172.30.48.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
5: docker0: mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:07:90:84:95 brd ff:ff:ff:ff:ff:ff
inet 172.30.48.1/21 brd 172.30.55.255 scope global docker0
valid_lft forever preferred_lft forever
到这里,flanneld 和 docker 之间网络建立完成。