二进制安装 kubernetes 1.12(二) - 安装docker, 部署Flannel网络

在 node 节点上安装 docker

参考 https://www.cnblogs.com/klvchen/p/8468855.html

Flannel 工作原理:

二进制安装 kubernetes 1.12(二) - 安装docker, 部署Flannel网络_第1张图片

部署Flannel网络

在 master上执行

# Falnnel要用etcd存储自身一个子网信息,所以要保证能成功连接Etcd,写入预定义子网段:
cd /opt/etcd/ssl

/opt/etcd/bin/etcdctl \
--ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem \
--endpoints="https://192.168.0.205:2379,https://192.168.0.206:2379,https://192.168.0.207:2379" \
set /coreos.com/network/config  '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'

下载 flannel-v0.10.0-linux-amd64.tar.gz

ansible node -m file -a 'path=/iba/tools state=directory'

ansible node -m command -a 'wget -O /iba/tools/flannel-v0.10.0-linux-amd64.tar.gz https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz'

ansible node -m file -a 'path=/opt/kubernetes/bin state=directory'
ansible node -m shell -a 'tar zxf /iba/tools/flannel-v0.10.0-linux-amd64.tar.gz -C /opt/kubernetes/bin/'  

systemd 管理 Flannel

mkdir /home/config && cd /home/config

cat > flanneld.service <<-'EOF'
[Unit] 
Description=Flanneld overlay address etcd agent 
After=network-online.target network.target 
Before=docker.service
 
[Service] 
Type=notify 
EnvironmentFile=/opt/kubernetes/cfg/flanneld 
ExecStart=/opt/kubernetes/bin/flanneld --ip-masq $FLANNEL_OPTIONS 
ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env 
Restart=on-failure
 
[Install] 
WantedBy=multi-user.target
EOF

ansible node -m copy -a 'src=flanneld.service dest=/usr/lib/systemd/system/flanneld.service'

配置Flannel

ansible node -m file -a 'path=/opt/kubernetes/cfg state=directory'

cat > flanneld << EOF
FLANNEL_OPTIONS="--etcd-endpoints=https://192.168.0.205:2379,https://192.168.0.206:2379,https://192.168.0.207:2379 -etcd-cafile=/opt/etcd/ssl/ca.pem -etcd-certfile=/opt/etcd/ssl/server.pem -etcd-keyfile=/opt/etcd/ssl/server-key.pem"
EOF

ansible node -m copy -a 'src=flanneld dest=/opt/kubernetes/cfg/flanneld'

配置Docker启动指定子网段

# 在node上执行
vi /usr/lib/systemd/system/docker.service 
# 在 for containers run by docker 下面添加,修改两行
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS -H unix://

启动 flannel 和 重启 docker

# 在 master 上执行
ansible node -m shell -a 'systemctl daemon-reload' 
ansible node -m shell -a 'systemctl start flanneld' 
ansible node -m shell -a 'systemctl status flanneld.service'
ansible node -m shell -a 'systemctl restart docker'

检查 docker 有没有在指定的 ip下启动

ansible node -m shell -a 'ps -ef|grep docker'

检查 docker0 与 flannel.1 在同一个网段

ansible node -m shell -a 'ip add'

转载于:https://www.cnblogs.com/klvchen/p/10305956.html

你可能感兴趣的:(二进制安装 kubernetes 1.12(二) - 安装docker, 部署Flannel网络)