K8s的flannel网络配置

K8s的flannel网络配置

1  k8s集群搭建完成(略)

2  k8s集群的网络安装配置

在master以及node节点安装网络需要的安装包

[root@master ~]# yum install flannel

修改master及node节点上的/etc/sysconfig/flanneld配置文件

修改结果如下所示

Master节点:

[root@master ~]# cat /etc/sysconfig/flanneld | grep -v "^#"

FLANNEL_ETCD_ENDPOINTS="http://192.168.248.171:2379"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

Node1节点

[root@node1 ~]# cat /etc/sysconfig/flanneld | grep -v "^#"

FLANNEL_ETCD_ENDPOINTS="http://192.168.248.171:2379"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

Node2节点

[root@node2 ~]# cat /etc/sysconfig/flanneld | grep -v "^#"

FLANNEL_ETCD_ENDPOINTS="http://192.168.248.171:2379"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

在master节点添加网络(该网络可以根据自己需要进行修改)

[root@master ~]#etcdctl mk //atomic.io/network/config '{"Network":"172.8.0.0/16"}'

3 master/node节点进行网络服务重启

Master节点

[root@master ~]# systemctl enable flannel

[root@master ~]# systemctl start flannel

Node节点

[root@node1 ~]# systemctl enable flannel

[root@node1 ~]# systemctl start flanneld

[root@node2 ~]# systemctl enable flannel

[root@node2 ~]# systemctl start flanneld

重启master节点上k8s服务

[root@master ~]# systemctl start kube-apiserver kube-controller-manager kube-scheduler docker

重启node节点上的k8s服务

[root@node1 ~]# systemctl restart kube-proxy kubelet docker

然后查看master节点及node节点上的网络服务,就会看到flannel网络已经配置完成

4 验证配置是否成功

启动两台容器,以实现k8s的调度原理,实现两天node节点各运行一个容器

[root@node2 ~]# docker ps

CONTAINER ID        IMAGE                                                        COMMAND                  CREATED             STATUS              PORTS               NAMES

e191d5fed66a        mysql:5.7.16                                                 "docker-entrypoint..."   17 minutes ago      Up 17 minutes                           k8s_mysql.f4f82081_mysql-1jf3v_default_1ce3272a-5758-11e9-99a4-000c29420128_7877c52d

38bdbd02f247        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           19 minutes ago      Up 19 minutes                           k8s_POD.1d520ba5_mysql-1jf3v_default_1ce3272a-5758-11e9-99a4-000c29420128_0d0b6e2f

[root@node1 ~]# docker ps

CONTAINER ID        IMAGE                                                        COMMAND                  CREATED             STATUS              PORTS               NAMES

5c9a64ff1eab        mysql:5.7.16                                                 "docker-entrypoint..."   18 minutes ago      Up 18 minutes                           k8s_mysql.f4f82081_mysql-9t28f_default_1ce2efaa-5758-11e9-99a4-000c29420128_4adbeb72

fefba2db4823        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           19 minutes ago      Up 19 minutes                           k8s_POD.1d520ba5_mysql-9t28f_default_1ce2efaa-5758-11e9-99a4-000c29420128_b5322f3b

启动mysql容器,登录到响应的容器验证是否可以互相ping通

推荐阅读更多精彩内容