您好,登錄后才能下訂單哦!
以下所有操作均在node節點進行
Flannel通過給每臺宿主機分配一個子網的方式為容器提供虛擬網絡,它基于Linux TUN/TAP,使用UDP/VXLAN封裝IP包來創建overlay網絡,并借助etcd(也支持kubernetes)維護網絡的分配情況。
角色 | 地址 | 安裝組件 |
---|---|---|
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引擎的安裝比較簡單這里就不多講解了,直接貼腳本刷即可。
腳本如下:
#!/bin/bash
#Docker引擎部署
#安裝依賴包
yum install yum-utils device-mapper-persistent-data lvm2 -y
#設置阿里云鏡像源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安裝Docker-ce
yum install -y docker-ce
#關閉防火墻及增強型安全功能
systemctl stop firewalld.service
setenforce 0
#啟動Docker并設置為開機自啟動
systemctl start docker.service
systemctl enable docker.service
#鏡像加速服務(每個人的阿里加速地址都不同,請自行前往阿里官網獲取)
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://123456.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
#網絡優化
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
service network restart
systemctl restart docker
#檢驗容器是否啟動完成
docker images
if [ $? -eq 0 ];then
echo "Docker啟動完成"
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}
//移動至工作目錄
[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
這里啟動后會生成一個flannel的虛擬網卡
[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網絡中) -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分配的網關
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。