node节点需要安装flannel网络插件才能保证所有的pod在一个局域网内通信,直接使用yum安装即可,版本是0.7.1.
1、安装flannel插件:
注意是2个node节点都需要安装,都需要修改service文件和配置文件。
yum install flannel -y
2、修改service文件/usr/lib/systemd/system/flanneld.service其内容为:
[Unit] Description=Flanneld overlay address etcd agent After=network.target After=network-online.target Wants=network-online.target After=etcd.service Before=docker.service [Service] Type=notify EnvironmentFile=/etc/sysconfig/flanneld EnvironmentFile=-/etc/sysconfig/docker-network ExecStart=/usr/bin/flanneld-start -etcd-endpoints=${FLANNEL_ETCD_ENDPOINTS} -etcd-prefix=${FLANNEL_ETCD_PREFIX} $FLANNEL_OPTIONS ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker Restart=on-failure [Install] WantedBy=multi-user.target RequiredBy=docker.service
提示:service文件中所有的变量参数都是读取相应的配置文件里面的,所有要保证前后对应。
修改其配置文件/etc/sysconfig/flanneld 内容如下:
# Flanneld configuration options # etcd url location. Point this to the server where etcd runs FLANNEL_ETCD_ENDPOINTS="https://10.10.90.105:2379,https://10.10.90.106:2379,https://10.10.90.107:2379" # etcd config key. This is the configuration key that flannel queries # For address range assignment #FLANNEL_ETCD_PREFIX="/atomic.io/network" FLANNEL_ETCD_PREFIX="/kube-centos/network" # Any additional options that you want to pass #FLANNEL_OPTIONS="" FLANNEL_OPTIONS="-etcd-cafile=/etc/kubernetes/ssl/ca.pem -etcd-certfile=/etc/kubernetes/ssl/kubernetes.pem -etcd-keyfile=/etc/kubernetes/ssl/kubernetes-key.pem"
以上2步是2个node节点都需要做的。
3、在etcd中常见网络配置信息
etcdctl --endpoints=https://10.10.90.105:2379,https://10.10.90.106:2379,https://10.10.90.107:2379 --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem mkdir /kube-centos/network #上下是2条命令,在任何节点上创建都行,因为etcd是集群的。 etcdctl --endpoints=https://10.10.90.105:2379,https://10.10.90.106:2379,https://10.10.90.107:2379 --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem mk /kube-centos/network/config '{"Network":"172.30.0.0/16","SubnetLen":24,"Backend":{"Type":"host-gw"}}'
4、启动flannel服务
systemctl daemon-reload
systemctl enable flanneld
systemctl start flanneld
systemctl status flanneld
5、核对相关配置信息:
#先声明个endpoint变量,后边好调用
[root@c7test_node1 ~]#ETCD_ENDPOINTS='https://10.10.90.105:2379,https://10.10.90.106:2379,https://10.10.90.107:2379'
[root@c7test_node1 ~]# etcdctl --endpoints=${ETCD_ENDPOINTS} --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernetes/ssl/kubernetes-key.pem ls /kube-centos/network/subnets
#输出 /kube-centos/network/subnets/172.30.87.0-24 /kube-centos/network/subnets/172.30.92.0-24 #说明,有几个node就有几个子网络,就有几条记录,我是2个node,分别安装了flannel插件
[root@c7test_node1 ~]# etcdctl --endpoints=${ETCD_ENDPOINTS}
--ca-file=/etc/kubernetes/ssl/ca.pem
--cert-file=/etc/kubernetes/ssl/kubernetes.pem
--key-file=/etc/kubernetes/ssl/kubernetes-key.pem
get /kube-centos/network/config
#输出
{"Network":"172.30.0.0/16","SubnetLen":24,"Backend":{"Type":"host-gw"}}
#此处是查看主网络配置
etcdctl --endpoints=${ETCD_ENDPOINTS} --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernete s/ssl/kubernetes-key.pem get /kube-centos/network/subnets/172.30.92.0-24
#输出
{"PublicIP":"10.10.90.106","BackendType":"vxlan","BackendData":{"VtepMAC":"26:af:ac:26:47:ad"}}
etcdctl --endpoints=${ETCD_ENDPOINTS} --ca-file=/etc/kubernetes/ssl/ca.pem --cert-file=/etc/kubernetes/ssl/kubernetes.pem --key-file=/etc/kubernete s/ssl/kubernetes-key.pem get /kube-centos/network/subnets/172.30.87.0-24
#输出
{"PublicIP":"10.10.90.107","BackendType":"vxlan","BackendData":{"VtepMAC":"82:6f:58:94:9f:59"}}
如有以上输出即代表flannel插件安装配置成功,下一篇文章开始安装node节点。