企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 1、部署前实验(现在是不同pod之间网络是不通的) 首先,flannel利用Kubernetes API或者etcd用于存储整个集群的网络配置,其中最主要的内容为设置集群的网络地址空间。例如,设定整个集群内所有容器的IP都取自网段“10.1.0.0/16”。 接着,flannel在每个主机中运行flanneld作为agent,它会为所在主机从集群的网络地址空间中,获取一个小的网段subnet,本主机内所有容器的IP地址都将从中分配。 然后,flanneld再将本主机获取的subnet以及用于主机间通信的Public IP,同样通过kubernetes API或者etcd存储起来。 最后,flannel利用各种backend mechanism,例如udp,vxlan等等,跨主机转发容器间的网络流量,完成容器间的跨主机通信。 ### 2、flannel官方下载 https://github.com/coreos/flannel wget https://github.com/coreos/flannel/releases/download/v0.11.0/flannel-v0.11.0-linux-amd64.tar.gz ``` mkdir /opt/flannel-v0.11.0 tar xf flannel-v0.11.0-linux-amd64.tar.gz -C /opt/flannel-v0.11.0/ ln -s /opt/flannel-v0.11.0/ /opt/flannel cd /opt/flannel mkdir cert ``` #### 在HDSS-79机器上分发证书 ``` [root@hdss7-200 certs]# scp ca.pem client-key.pem client.pem hdss21-200:/opt/flannel/cert root@hdss7-200's password: ca.pem 100% 1350 1.3MB/s 00:00 client-key.pem 100% 1675 1.2MB/s 00:00 client.pem 100% 1371 1.8MB/s 00:00 ``` #### 创建配置 ``` [root@hdsss7-21 flannel]# pwd /opt/flannel [root@hdss7-21 flannel]# cat subnet.env FLANNEL_NETWORK=172.7.0.0/16 FLANNEL_SUBNET=172.7.21.1/24 FLANNEL_MTU=1500 FLANNEL_IPMASQ=false ``` #### 创建启动脚本 ``` [root@hdss7-21 flannel]# vim flannel.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 chmod +x /opt/flannel/flannel.sh mkdir -p /data/logs/flanneld ``` #### 操作etcd,增加host-gw 在HDSS7-21.host.com上操作: ``` /opt/etcd目录下操作 [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"}} [root@hdss7-21 etcd]# ./etcdctl get /coreos.com/network/config {"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}} ``` #### 启动文件配置 ``` vi /etc/supervisord.d/flannel.ini [program:flanneld] 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) ``` #### 更新配置查看启动 ``` supervisorctl update supervisorctl status ``` #### 3、在回来测试现在可以ping通了 ![](https://img.kancloud.cn/83/39/83396e2e304cd2c9077166b274c7f32c_863x367.png) #### 为什么可以通其实就是添加了静态路由 ![](https://img.kancloud.cn/ee/a8/eea87d973f3b93179cdc9bd8470f0180_572x129.png)