kubelet集羣網絡配置flannel(覆蓋網絡)

kubernetes自己並不會對跨主機容器的網絡進行設置,這須要額外的工具來實現。一些經常使用的開源工具主要包括flanne、OpenvSwitch、Weave、Calico等,這裏面最經常使用的是flannel、OpenvSwitch和直接路由這3種配置。node

1)安裝etcdgit

因爲flannel使用etcd做爲數據庫,因此須要預先安裝etcd。能夠參照上一篇。github

2)安裝flanneldocker

須要在每臺node上都安裝flannel。flannel的下載地址數據庫

將下載的二進制包進行解壓,而後將flanneld和mk-docker-opts.sh複製到/usr/bin目錄下,便可完成簡單安裝。bash

3)配置flannel網絡

此處以systemd系統爲例對flanneld服務進行配置。工具

cat /usr/lib/systemd/system/flanneld.service
[Unit]
Description=flanneld overlay address etcd agent
Documentation=https://github.com/coreos/flannel
After=network.service
Before=docker.service


[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/flanneld
ExecStart=/usr/bin/flanneld --etcd-endpoints=${FLANNEL_ETCD} $FLANNEL_OPTIONS


[Install]
RequiredBy=docker.service
WantedBy=multi-user.target

編輯配置文件/etc/sysconfig/flanneld,而且設置etcd的地址。ui

cat /etc/sysconfig/flanneld

#flanneld configuration options

#etcd url location. Point this to the server where etcd runs 

FLANNEL_ETCD="http://192.168.142.161:2379,http://192.168.142.162:2379,http://192.168.142.163:2379"

# etcd config key. this is the configuration key that flannel queries
# for address range assignment
FLANNEL_ETCD_KEY="/coreos.com/network"

在啓動flanneld服務以前,須要在etcd中添加一條網絡配置記錄,這個配置將用於flanneld分配給每一個docker的虛擬IP地址段。this

etcdctl set /coreos.com/network/config '{ "Network": "10.1.0.0/16" }

4)因爲flanneld將覆蓋docker0網橋,因此若是docker服務已經啓動,則中止docker服務。

5)啓動flanneld服務

systemctl restart flanneld

6)設置docker0網橋的ip地址

mk-docker-opts.sh -i
source /run/flannel/subnet.env
ifconfig docker0 ${FLANNEL_SUBNET}

完成後確認網絡接口docker0的IP地址屬於flannel0的子網

[root@kubernets-node2 ~]# ip add sh

4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:22:3b:9f:2e brd ff:ff:ff:ff:ff:ff
    inet 10.1.60.1/24 brd 10.1.60.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:22ff:fe3b:9f2e/64 scope link 
       valid_lft forever preferred_lft forever
6: vethf488ee1@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP 
    link/ether 9a:38:bd:bb:88:c7 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::9838:bdff:febb:88c7/64 scope link

7)從新啓動docker服務

systemctl restart docker
相關文章
相關標籤/搜索