文章目錄
- 1、環境準備
- 2、docker引擎部署
- 3、flannel網路配置
- 3.1、寫入分配的子網段到ETCD中,供flannel使用
- 3.2、查看寫入的資訊
- 3.3、拷貝到所有node節點(只需要部署在node節點即可)
- 3.4、所有node節點操作解壓
- 3.5、開啟flannel網路功能
- 3.6、配置docker連接flannel
- 3.7、重啟docker服務
- 3.8、查看flannel網路
1、環境準備
共需要3臺虛擬機
1臺作為master
2臺作為node節點
2、docker引擎部署
所有node節點部署docker引擎
詳見docker安裝腳本
Docker的(理論+安裝)
Docker鏡像加速
這是在node節點上必須配置的
3、flannel網路配置
Overlay Network:覆寫網路,在基礎網路上疊加的一種虛擬網路技術模式,該網路中的主機通過虛擬鏈路連接起來,
VXLAN:將源資料包封裝到UDP中,并使用基礎網路的IP/MAC作為外層報文頭進行封裝,然后在以太網上傳輸,到達目的地后由隧道端點解封裝并將資料發送給目
標地址,
Flannel:是Overlay網路的一 種, 也是將源資料包封裝在另一種網路 包里面進行路由轉發和通信,目前已經支持UDP、VXLAN、 AWS VPC和GCE路由等資料轉發方
式,
配置的時候要將這幅圖看一下

3.1、寫入分配的子網段到ETCD中,供flannel使用
master操作
[root@localhost etcd-cert]# /opt/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.162.10:2379,https://192.168.162.30:2379,https://192.168.162.40:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}
3.2、查看寫入的資訊
[root@localhost etcd-cert]# /opt/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.162.10:2379,https://192.168.162.30:2379,https://192.168.162.40:2379" get /coreos.com/network/config
{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}
3.3、拷貝到所有node節點(只需要部署在node節點即可)
[root@localhost k8s]# scp flannel-v0.10.0-linux-amd64.tar.gz root@192.168.162.30:/root
[root@localhost k8s]# scp flannel-v0.10.0-linux-amd64.tar.gz root@192.168.162.40:/root
3.4、所有node節點操作解壓
[root@localhost ~]# tar zxvf flannel-v0.10.0-linux-amd64.tar.gz
flanneld
mk-docker-opts.sh
README.md
//k8s作業目錄
[root@localhost ~]# mkdir /opt/kubernetes/{cfg,bin,ssl} -p
[root@localhost ~]# mv mk-docker-opts.sh flanneld /opt/kubernetes/bin/
[root@localhost ~]# vim flannel.sh
#!/bin/bash
ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}
cat <<EOF >/opt/kubernetes/cfg/flanneld
FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \
-etcd-cafile=/opt/etcd/ssl/ca.pem \
-etcd-certfile=/opt/etcd/ssl/server.pem \
-etcd-keyfile=/opt/etcd/ssl/server-key.pem"
EOF
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
systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld
3.5、開啟flannel網路功能
[root@localhost ~]# bash flannel.sh https://192.168.162.10:2379,https://192.168.162.30:2379,https://192.168.162.40:2379
Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.
3.6、配置docker連接flannel
看好這個格式,不要自己需改,就按照下面的配置就行
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
[root@localhost ~]# cat /run/flannel/subnet.env
DOCKER_OPT_BIP="--bip=172.17.42.1/24"
DOCKER_OPT_IPMASQ="--ip-masq=false"
DOCKER_OPT_MTU="--mtu=1450"
//說明:bip指定啟動時的子網
DOCKER_NETWORK_OPTIONS=" --bip=172.17.42.1/24 --ip-masq=false --mtu=1450"
3.7、重啟docker服務
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
3.8、查看flannel網路
[root@localhost ~]# ifconfig


測驗ping通對方docker0網卡 證明flannel起到路由作用

[root@localhost ~]# docker run -it centos:7 /bin/bash
[root@5f9a65565b53 /]# yum install net-tools -y
[root@3f7ae4f27c85 /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
inet 172.17.84.2 netmask 255.255.255.0 broadcast 172.17.84.255
ether 02:42:ac:11:54:02 txqueuelen 0 (Ethernet)
RX packets 20172 bytes 15438714 (14.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9838 bytes 534863 (522.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
再次測驗ping通兩個node中的centos:7容器

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/275895.html
標籤:其他
下一篇:7:Linux-行程信號

