kubernetes容器集群管理-Flannel网络配置

拥有回忆 提交于 2020-02-29 12:30:23

目录

 

1、master分配地址池

2、两台节点机器安装flannel

3、两台节点机器分别执行flannel.sh脚本

4、验证flannel是否生效


1、master分配地址池

#利用etcd给flannel分配网段

[root@master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.192.128:2379,https://192.168.192.129:2379,https://192.168.192.130:2379" set /coreos.com/network/config '{ "Network": "172.18.0.0/16", "Backend": {"Type": "vxlan"}}'

#利用etcd查看flannel已分配网段(两台节点配置完成后查看)

[root@manage01 ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.192.128:2379,https://192.168.192.129:2379,https://192.168.192.130:2379" ls /coreos.com/network/subnets
/coreos.com/network/subnets/172.18.56.0-24
/coreos.com/network/subnets/172.18.70.0-24

2、两台节点机器安装flannel

[root@mangge01 soft]# wget https://github.com/coreos/flannel/releases/tag/v0.9.1/flannel-0.9.1.tar.gz
[root@mangge01 soft]# tar zxvf flannel-v0.9.1-linux-amd64.tar.gz 
[root@mangge01 soft]# scp -r flanneld mk-docker-opts.sh root@192.168.192.129:/opt/kubernetes/bin/
[root@mangge01 soft]# scp -r flanneld mk-docker-opts.sh root@192.168.192.130:/opt/kubernetes/bin/

3、两台节点机器分别执行flannel.sh脚本

[root@node02 ~]# cd /opt/kubernetes/bin/
[root@node02 bin]# vi flannel130.sh && chmod 755 flannel130.sh
[root@node02 bin]# ./flannel130.sh

#!/bin/bash

ETCD_ENDPOINTS="https://192.168.192.128:2379,https://192.168.192.129:2379,https://192.168.192.130:2379"

# "flannel配置文件,配置所管理主机与引用证书"
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

# "创建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

# "修改docker启动/配置文件使用FLANNEL网络"
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

4、验证flannel是否生效

#发现docker和flnnel地址网段全部变为172.18网段,即之前etcd统一规划的网段

[root@node02 bin]# ip a
docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:45:dd:79:12 brd ff:ff:ff:ff:ff:ff
    inet 172.18.70.1/24 brd 172.18.70.255 scope global docker0
       valid_lft forever preferred_lft forever
flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default 
    link/ether 12:0c:57:12:ce:7d brd ff:ff:ff:ff:ff:ff
    inet 172.18.70.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
    inet6 fe80::100c:57ff:fe12:ce7d/64 scope link 
       valid_lft forever preferred_lft forever

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!