Flannel Network for K8S Deployment

Keywords: Kubernetes network Docker SSL

1.flannel Download

flannel download address https://github.com/coreos/flannel/releases
Select the appropriate version from github and download it wget as follows:
wget https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz

Unzip with tar-zxvf flannel-v0.10.0-linux-amd64.tar.gz file after download is complete
cd flannel-v0.10.0-linux-amd64 enters the directory Copy the file named flannel to the directory you want to install
flannel is installed only from the slave node, not from the primary node

To use flannel, you need to create new flannel network information in etcd

/opt/kubernetes/bin/etcdctl --ca-file=/opt/kubernetes/ssl/ca.pem --cert-file=/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --endpoints="https://192.168.2.115:2379,https://192.168.2.121:2379,https://192.168.2.123:2379" set /coreos.com/network/config '{"Network":"172.17.0.0/16","Backend":{"Type":"vxlan"}}'

The purpose of this command is to add flannel network information to etcd

2.flannel profile

ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}

cat <<EOF >/opt/kubernetes/cfg/flanneld

FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \
-etcd-cafile=/opt/kubernetes/ssl/ca.pem \
-etcd-certfile=/opt/kubernetes/ssl/server.pem \
-etcd-keyfile=/opt/kubernetes/ssl/server-key.pem"

EOF

3. Generate service configuration file for flannel

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

4. Modify docker's service profile

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
cp flanneld.service /usr/lib/systemd/system
cp docker.service /usr/lib/systemd/system

Now that all our configuration files have been generated, you just need to copy them to the appropriate directory to start the service
After flannel starts, we'll restart the docker service to join the flannel network

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

Posted by AdamBrill on Sun, 01 Mar 2020 08:19:23 -0800