Binary deployment of Flannel network

Step by step

The binary deployment of Flannel is divided into the following steps

  • Write the allocated subnet to etcd for use by flannel
  • Download the binary package
  • Deploy and configure flannel (node ​​node)
  • systemd manages Flannel
  • Configure the subnet generated by Flannel used by Docker
  • Start Flannel

1. Node IP

lnhMaster01 192.168.176.128
lnhNode01 192.168.176.135
lnhNode02 192.168.176.137

2. Download the flannel binary file
wget https://github.com/coreos/flannel/releases/download/v0.12.0/flannel-v0.12.0-linux-amd64.tar.gz and
unzip the two executable files flanneld, Copy mk-docker-opts.sh to /opt/kubernetes/bin

3. The linMaster02 node stores the flannel network configuration in etcd

/opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.176.128:2379,https://192.168.176.135:2379,https://192.168.176.137:2379" set /coreos.com/network/config '{"Network": "172.15.0.0/16", "Backend": {"Type": "vxlan"}}'

4.lnhNode01 node: Edit the flannel configuration file /opt/kubernetes/cfg/flanneld

Note: Both lnhNode01 and lnhNode00 have the certificate files in the lnhMaster01 /opt/etcd/ssl/ directory

FLANNEL_OPTIONS="-etcd-cafile=/opt/etcd/ssl/ca.pem -etcd-certfile=/opt/etcd/ssl/server.pem -etcd-keyfile=/opt/etcd/ssl/server-key.pem "

5.lnhNode01 node: Edit the flannel.sh script to generate flanned.service, and configure docker.service to use the network allocated by flannel

#!/bin/bash

cat <<EOF >/usr/lib/systemd/system/flanneld.service
[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

cat <<EOF >/usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd  \$DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld
systemctl restart docker

6. lnhNode01 node: execute ./flannel.sh, and after success, a /run/flannel/subnet.env file will be generated to record the ip that can be allocated by the machine

7.lnhNode02 performs the same operation as lnhNode01 to configure the flannel network

8. Check if flannel is successfully configured

首先看flanneld.service服务是否正常启动
如果正常启动,执行route命令看是否有flannel路由信息
ifconfig 查看是否有flannel开头的桥接网卡信息
如果以上都正常,那么用node1的docker0和node2的docker0相互ping,是可以ping通的

Reference learning: https://blog.csdn.net/zhenliang8

Guess you like

Origin blog.csdn.net/qq_37640410/article/details/108989900