您好,登錄后才能下訂單哦!
以下所有操作均在node節(jié)點(diǎn)進(jìn)行
Flannel通過給每臺(tái)宿主機(jī)分配一個(gè)子網(wǎng)的方式為容器提供虛擬網(wǎng)絡(luò),它基于Linux TUN/TAP,使用UDP/VXLAN封裝IP包來創(chuàng)建overlay網(wǎng)絡(luò),并借助etcd(也支持kubernetes)維護(hù)網(wǎng)絡(luò)的分配情況。
角色 | 地址 | 安裝組件 |
---|---|---|
master | 192.168.142.220 | kube-apiserver kube-controller-manager kube-scheduler etcd |
node1 | 192.168.142.136 | kubelet kube-proxy docker flannel etcd |
node2 | 192.168.142.132 | kubelet kube-proxy docker flannel etcd |
docker引擎的安裝比較簡(jiǎn)單這里就不多講解了,直接貼腳本刷即可。
腳本如下:
#!/bin/bash
#Docker引擎部署
#安裝依賴包
yum install yum-utils device-mapper-persistent-data lvm2 -y
#設(shè)置阿里云鏡像源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安裝Docker-ce
yum install -y docker-ce
#關(guān)閉防火墻及增強(qiáng)型安全功能
systemctl stop firewalld.service
setenforce 0
#啟動(dòng)Docker并設(shè)置為開機(jī)自啟動(dòng)
systemctl start docker.service
systemctl enable docker.service
#鏡像加速服務(wù)(每個(gè)人的阿里加速地址都不同,請(qǐng)自行前往阿里官網(wǎng)獲?。?tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://123456.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
#網(wǎng)絡(luò)優(yōu)化
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
service network restart
systemctl restart docker
#檢驗(yàn)容器是否啟動(dòng)完成
docker images
if [ $? -eq 0 ];then
echo "Docker啟動(dòng)完成"
else
echo "ERROR"
systemctl status docker
exit 1
fi
[root@node2 bin]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem \
--cert-file=/opt/etcd/ssl/server.pem \
--key-file=/opt/etcd/ssl/server-key.pem \
--endpoints="https://192.168.142.220:2379,https://192.168.142.136:2379,https://192.168.142.132:2379" set /coreos.com/network/config '{"Network":"172.17.0.0/16","Backend":{"Type":"vxlan"}}'
[root@node2 ~]# tar zxvf flannel-v0.10.0-linux-amd64.tar.gz
flanneld
mk-docker-opts.sh
README.md
//建立工作目錄
[root@node2 ~]# mkdir -p /opt/kubernetes/{cfg,ssl,bin}
//移動(dòng)至工作目錄
[root@node2 ~]# mv flanneld mk-docker-opts.sh /opt/kubernetes/bin/
[root@node2 ~]# cat <<EOF >/opt/kubernetes/cfg/flanneld.cfg
FLANNEL_OPTIONS="--etcd-endpoints=https://192.168.142.220:2379,https://192.168.142.132:2379,https://192.168.142.136:2379 \
-etcd-cafile=/opt/etcd/ssl/ca.pem \
-etcd-certfile=/opt/etcd/ssl/server.pem \
-etcd-keyfile=/opt/etcd/ssl/server-key.pem
EOF
[root@node2 ~]# 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.cfg
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
[root@node2 bin]# chmod +x /usr/lib/systemd/system/flanneld.service
[root@node2 bin]# systemctl start flanneld.service
[root@node2 bin]# systemctl status flanneld.service
[root@node2 bin]# systemctl enable flanneld.service
這里啟動(dòng)后會(huì)生成一個(gè)flannel的虛擬網(wǎng)卡
[root@node2 bin]# vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env //添加這一行
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS(添加該變量,加入flannel網(wǎng)絡(luò)中) -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
[root@node2 bin]# cat /run/flannel/subnet.env
DOCKER_OPT_BIP="--bip=172.17.34.1/24" //給docker分配的網(wǎng)關(guān)
DOCKER_OPT_IPMASQ="--ip-masq=false"
DOCKER_OPT_MTU="--mtu=1450"
DOCKER_NETWORK_OPTIONS=" --bip=172.17.34.1/24 --ip-masq=false --mtu=1450"
[root@node2 bin]# systemctl daemon-reload
[root@node2 bin]# systemctl restart docker
node1→node2
node2→node1
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。