Flannel, CNI network plug-in of kubernetes

Posted by frymaster on Mon, 06 Apr 2020 16:33:17 +0200

Operation and maintenance technology exchange group: 926402931, welcome to exchange.

Catalog

1. Cluster architecture

host name role IP address
hdss7-21.host.com flannel 10.4.7.21
hdss7-22.host.com flannel 10.4.7.22

Taking hdss7-21.host.com as an example

1.1. Download the software, unzip it, and make a soft link
[root@hdss7-21 ~]# cd /opt/src/
[root@hdss7-21 src]# wget https://github.com/coreos/flannel/releases/download/v0.11.0/flannel-v0.11.0-linux-amd64.tar.gz

[root@hdss7-21 src]# mkdir /opt/flannel-v0.11.0
[root@hdss7-21 src]# tar xf flannel-v0.11.0-linux-amd64.tar.gz  -C /opt/flannel-v0.11.0/
[root@hdss7-21 src]# ln -s /opt/flannel-v0.11.0/ /opt/flannel
1.2. Create directory
[root@hdss7-21 src]# /opt/flannel
[root@hdss7-21 flannel]# mkdir /opt/flannel/cert
1.3. Copy certificate documents
[root@hdss7-21 flannel]# cd cert
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/ca.pem .
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/client.pem .
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/client-key.pem .
1.4. Create configuration
[root@hdss7-21 cert]# cd ..
[root@hdss7-21 flannel]# vi subnet.env
FLANNEL_NETWORK=172.7.0.0/16
FLANNEL_SUBNET=172.7.21.1/24
FLANNEL_MTU=1500
FLANNEL_IPMASQ=false
1.5. Create startup script
[root@hdss7-21 flannel]# vi flanneld.sh
#!/bin/sh
./flanneld \
  --public-ip=10.4.7.21 \
  --etcd-endpoints=https://10.4.7.12:2379,https://10.4.7.21:2379,https://10.4.7.22:2379 \
  --etcd-keyfile=./cert/client-key.pem \
  --etcd-certfile=./cert/client.pem \
  --etcd-cafile=./cert/ca.pem \
  --iface=eth0 \
  --subnet-file=./subnet.env \
  --healthz-port=2401
1.6. Authorize and create log directory
[root@hdss7-21 flannel]# chmod +x flanneld.sh 
[root@hdss7-21 flannel]# mkdir -p /data/logs/flanneld
1.7. Create supervisor configuration
[root@hdss7-21 flannel]# vi /etc/supervisord.d/flannel.ini
[program:flanneld-7-21]
command=/opt/flannel/flanneld.sh                             ; the program (relative uses PATH, can take args)
numprocs=1                                                   ; number of processes copies to start (def 1)
directory=/opt/flannel                                       ; directory to cwd to before exec (def no cwd)
autostart=true                                               ; start at supervisord start (default: true)
autorestart=true                                             ; retstart at unexpected quit (default: true)
startsecs=30                                                 ; number of secs prog must stay running (def. 1)
startretries=3                                               ; max # of serial start failures (default 3)
exitcodes=0,2                                                ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT                                              ; signal used to kill process (default TERM)
stopwaitsecs=10                                              ; max num secs to wait b4 SIGKILL (default 10)
user=root                                                    ; setuid to this UNIX account to run the program
redirect_stderr=true                                         ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/flanneld/flanneld.stdout.log       ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB                                 ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4                                     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB                                  ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false                                  ; emit events on stdout writes (default false)

2. Flannel host GW model (one out of three)

[root@hdss7-21 etcd]# ./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}'
{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}
//Verification:
[root@hdss7-21 etcd]# ./etcdctl get /coreos.com/network/config
{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}
2.1. Start service and check
[root@hdss7-21 flannel]# supervisorctl  update
[root@hdss7-21 flannel]# supervisorctl status

3.flannel vxlan model (one out of three)

1.supervisor stop flanneld-7-[21.22]
2.delete host-gw Route created by model
route del -net 172.7.21.0/24 gw 10.4.7.21     hdss7-22.host.com upper
route del -net 172.7.22.0/24 gw 10.4.7.22     hdss7-21.host.com upper
3.stay etcd modify
./etcdctl get /coreos.com/network/config
./etcdctl rm /coreos.com/network/config
./etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN"}}'
4.supervisor start flanneld-7-[21.22]

4.flannel direct routing model (one out of three)

'{"Network": "172.7.0.0/16", "Backend": {"Type": "VxLAN","Directrouting": true}}'

Topics: Linux network supervisor github