K8S部署之Flannel网络
1.flannel下载flannel下载地址 https://github.com/coreos/flannel/releases从github 选相应的版本用wget方式下载 如:wget https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz下载...
·
1.flannel下载
flannel下载地址 https://github.com/coreos/flannel/releases
从github 选相应的版本用wget方式下载 如:
wget https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz
下载完成后用 tar -zxvf flannel-v0.10.0-linux-amd64.tar.gz 文件解压
cd flannel-v0.10.0-linux-amd64 进入目录 把名为flannel的文件复制到要安装的目录
flannel 只在从节点上安装,主节点上不安装
要想使用flannel需要在etcd中新建flannel的网络信息
/opt/kubernetes/bin/etcdctl --ca-file=/opt/kubernetes/ssl/ca.pem --cert-file=/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --endpoints="https://192.168.2.115:2379,https://192.168.2.121:2379,https://192.168.2.123:2379" set /coreos.com/network/config '{"Network":"172.17.0.0/16","Backend":{"Type":"vxlan"}}'
这个命令的作用是把flannel网络信息添加到etcd
2.flannel配置文件
ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}
cat <<EOF >/opt/kubernetes/cfg/flanneld
FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \
-etcd-cafile=/opt/kubernetes/ssl/ca.pem \
-etcd-certfile=/opt/kubernetes/ssl/server.pem \
-etcd-keyfile=/opt/kubernetes/ssl/server-key.pem"
EOF
3.生成flannel的服务配置文件
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
4.修改docker的服务配置文件
cat <<EOF >/usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd \$DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
cp flanneld.service /usr/lib/systemd/system
cp docker.service /usr/lib/systemd/system
到此我们所有的配置文件都已经生成,只需要把文件复制到相应的目录就可以启动服务了
flannel启动完之后我们还要重启一下docker服务让其加入到flannel网络中
systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld
systemctl restart docker
更多推荐
已为社区贡献4条内容
所有评论(0)