Kubernetes安装系列之Docker安装与设定

这篇文章整理以下Node节点的docker的安装与设定方法,本文以脚本的方式进行固化,内容仍然放在github的easypack上。

整体操作

  • https://blog.csdn.net/liumiaocn/article/details/88413428

docker的设定文件

[root@host131 shell]# cat /etc/docker/docker.conf 
DOCKER_OPTS="--registry-mirror=https://hub-mirror.c.163.com \
-H tcp://0.0.0.0:4243 \
-H unix:///var/run/docker.sock \
--selinux-enabled=false \
--log-opt max-size=1g"
[root@host131 shell]#

Systemd服务配置文件

[root@host131 shell]# cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io

[Service]
EnvironmentFile=-/run/flannel/docker
EnvironmentFile=-/etc/docker/docker.conf
ExecStart=/usr/local/bin/dockerd $DOCKER_NETWORK_OPTIONS $DOCKER_OPTS
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target
[root@host131 shell]#

脚本示例

[root@host131 shell]# cat step7-install-docker.sh 
#!/bin/sh

. ./install.cfg

echo -e "\n##  docker service"
systemctl stop docker 2>/dev/null

mkdir -p ${ENV_DOCKER_DIR_BIN} ${ENV_DOCKER_DIR_ETC} 
chmod 755 ${ENV_HOME_DOCKER}/*
cp -p ${ENV_HOME_DOCKER}/docker* ${ENV_DOCKER_DIR_BIN}
if [ $? -ne 0 ]; then
  echo "please check docker binary files existed in ${ENV_HOME_DOCKER}/ or not"
  exit 
fi

# create docker configuration file
cat >${ENV_DOCKER_DIR_ETC}/${ENV_DOCKER_ETC} <<EOF
DOCKER_OPTS="--registry-mirror=${ENV_DOCKER_REGISTRY_MIRROR} \\
-H tcp://0.0.0.0:4243 \\
-H unix:///var/run/docker.sock \\
--selinux-enabled=false \\
--log-opt max-size=${ENV_DOCKER_OPT_LOG_MAX_SIZE}"
EOF

# Create the docker service.
cat >${ENV_DOCKER_SERVICE} <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io

[Service]
EnvironmentFile=-${ENV_DOCKER_FLANNEL_CONF}
EnvironmentFile=-${ENV_DOCKER_DIR_ETC}/${ENV_DOCKER_ETC}
ExecStart=${ENV_DOCKER_DIR_BIN}/dockerd \$DOCKER_NETWORK_OPTIONS \$DOCKER_OPTS
ExecReload=/bin/kill -s HUP \$MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target
EOF

echo -e "\n##  daemon reload service "
systemctl daemon-reload
echo -e "\n##  start docker service "
systemctl start docker
echo -e "\n##  enable docker service " 
systemctl enable docker
echo -e "\n##  check  docker status"
systemctl status docker

echo
echo -e "##  check docker version"
docker version
[root@host131 shell]# 

执行示例

[root@host131 shell]# sh step7-install-docker.sh 

##  docker service

##  daemon reload service 

##  start docker service 

##  enable docker service 

##  check  docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-03-24 17:52:41 CST; 226ms ago
     Docs: http://docs.docker.io
 Main PID: 4949 (dockerd)
   CGroup: /system.slice/docker.service
           ├─4949 /usr/local/bin/dockerd --bip=172.200.240.1/21 --ip-masq=false --mtu=1450 --registry-mirror=https://hub-mirror.c.163.com -H tcp://0.0.0.0...
           └─4952 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /va...

Mar 24 17:52:41 host131 systemd[1]: Started Docker Application Container Engine.
Mar 24 17:52:42 host131 dockerd[4949]: time="2019-03-24T17:52:42.015287389+08:00" level=warning msg="[!] DON'T BIND ON ANY IP ADDRESS WITHOUT set...OING [!]"
Mar 24 17:52:42 host131 dockerd[4949]: time="2019-03-24T17:52:42.034052032+08:00" level=info msg="libcontainerd: new containerd process, pid: 4952"
Hint: Some lines were ellipsized, use -l to show in full.

##  check docker version
Client:
 Version:      17.03.2-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   f5ec1e2
 Built:        Tue Jun 27 01:35:00 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.2-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   f5ec1e2
 Built:        Tue Jun 27 01:35:00 2017
 OS/Arch:      linux/amd64
 Experimental: false
[root@host131 shell]#

flannel设定之后各node节点都会统一管理ip,不同容器之间的互联互通成为可能,本文的docker安装是在flannel的网络设定基础之上的,可以看到如下docker0已经使用flannel的配置了。

[root@host131 shell]# ip addr show docker0
8: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:73:01:b1:6d brd ff:ff:ff:ff:ff:ff
    inet 172.200.240.1/21 scope global docker0
       valid_lft forever preferred_lft forever
[root@host131 shell]# ip addr show flannel.1
5: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default 
    link/ether 22:22:02:92:1e:74 brd ff:ff:ff:ff:ff:ff
    inet 172.200.240.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
    inet6 fe80::2022:2ff:fe92:1e74/64 scope link 
       valid_lft forever preferred_lft forever
[root@host131 shell]# 

你可能感兴趣的:(Kubernetes,深入浅出kubernetes)