您好,登錄后才能下訂單哦!
本文以用Flannel網絡插件為例,為大家分析kubernetes安裝Flannel網絡插件的方法以及Flannel的工作原理。閱讀完整文相信大家對Flannel以及Flannel的工作原理有了一定的認識。
1、CNI網絡插件最主要的功能就是實現POD資源能夠跨宿主機是進行能信
#test-nodes1主機無法ping通test-nodes2主機的pod容器 [root@test-nodes1 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-ds1-qg45q 1/1 Running 0 2d12h 172.7.22.3 test-nodes2.cedarhd.com <none> <none> nginx-ds1-whnmv 1/1 Running 0 2d12h 172.7.21.3 test-nodes1.cedarhd.com <none> <none> [root@test-nodes1 ~]# ping 172.7.22.3 PING 172.7.22.3 (172.7.22.3) 56(84) bytes of data. ^C --- 172.7.22.3 ping statistics --- 8 packets transmitted, 0 received, 100% packet loss, time 6999ms
#此操作分別需要在test-nodes1與test-nodes2上操作 [root@test-nodes1 ~]# cd /opt/src/ [root@test-nodes1 src]# wget https://github.com/coreos/flannel/releases/download/v0.11.0/flannel-v0.11.0-linux-amd64.tar.gz [root@test-nodes1 src]# mkdir /opt/flannel-v0.11.0 [root@test-nodes1 src]# tar xf flannel-v0.11.0-linux-amd64.tar.gz -C /opt/flannel-v0.11.0/ [root@test-nodes1 src]# ln -s /opt/flannel-v0.11.0/ /opt/flannel [root@test-nodes1 src]# cd /opt/flannel [root@test-nodes1 flannel]# mkdir cert [root@test-nodes1 flannel]# cd cert/ [root@test-nodes1 cert]# scp test-operator:/opt/certs/ca.pem . root@test-operator's password: ca.pem 100% 1346 173.2KB/s 00:00 [root@test-nodes1 cert]# scp test-operator:/opt/certs/client.pem . root@test-operator's password: client.pem 100% 1363 207.0KB/s 00:00 [root@test-nodes1 cert]# scp test-operator:/opt/certs/client-key.pem . root@test-operator's password: client-key.pem [root@test-nodes1 cert]# cd .. flannel]# vi subnet.env FLANNEL_NETWORK=172.7.0.0/16 FLANNEL_SUBNET=172.7.21.1/24 #每個nodes的子網不一樣需修改,test-nodes1為21,而test-nodes2為22 FLANNEL_MTU=1500 FLANNEL_IPMASQ=false flannel]# vi flanneld.sh #!/bin/sh ./flanneld \ --public-ip=10.3.153.221 \ #另外一臺test-nodes2需要修改 --etcd-endpoints=https://10.3.153.212:2379,https://10.3.153.221:2379,https://10.3.153.222:2379 \ --etcd-keyfile=./cert/client-key.pem \ --etcd-certfile=./cert/client.pem \ --etcd-cafile=./cert/ca.pem \ --iface=ens33 \ --subnet-file=./subnet.env \ --healthz-port=2401 [root@test-nodes1 flannel]# cd /opt/etcd # 下面這一步在一步機器上執行即可,只需執行一次 [root@test-nodes1 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"}} [root@test-nodes1 etcd]# 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) [root@test-nodes1 etcd]# supervisorctl update flanneld-7-21: added process group [root@test-nodes1 flannel]# supervisorctl status etcd-server-7-21 RUNNING pid 14828, uptime 2 days, 14:55:02 flanneld-7-21 RUNNING pid 26991, uptime 0:00:48 kube-apiserver-7-21 RUNNING pid 14810, uptime 2 days, 14:56:17 kube-controller-manager-7-21 RUNNING pid 14868, uptime 2 days, 14:46:46 kube-kubelet-7-21 RUNNING pid 15095, uptime 2 days, 13:46:15 kube-proxy-7-21 RUNNING pid 22013, uptime 2 days, 13:05:18 kube-scheduler-7-21 RUNNING pid 25120, uptime 2 days, 12:53:29
1、host-gw模型,兩臺運算節點在同一個網段,當flannel啟動時會為兩臺運算節點增加相應的路由表,此時兩臺運算節點的POD就能互相通信,而flannel退出也不會影響,因為路由表已添加到宿主機。
2、VxLAN模型,兩臺運算節點在不同的網段
看完上述內容,你們對Flannel以及Flannel的工作原理有進一步的了解嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。