1下载部署flannel

创建目录(三台操作)

mkdir -p /app/kubernetes/{cfg,bin,ssl}

tar zxvf  flannel-v0.10.0-linux-amd64.tar.gz

cp flanneld  mk-docker-opts.sh /app/kubernetes/bin/

scp   /app/kubernetes/bin/* k8s-node01:/app/kubernetes/bin/

scp   /app/kubernetes/bin/* k8s-node02:/app/kubernetes/bin/

 

k8s-master-01上执行执行

 

cd /app/etcd/ssl

/app/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.159.121:2379,https://192.168.159.122:2379,https://192.168.159.123:2379" set /coreos.com/network/config '{"Network": "172.18.0.0/16","Backend":{"Type":"vxlan"}}'

 

2、三台部署flannel服务

配置flannel

vi /app/kubernetes/cfg/flanneld

 

FLANNEL_OPTIONS="--etcd-endpoints=https://192.168.159.121:2379,https://192.168.159.122:2379,https://192.168.159.123:2379 -etcd-cafile=/app/etcd/ssl/ca.pem -etcd-certfile=/app/etcd/ssl/server.pem -etcd-keyfile=/app/etcd/ssl/server-key.pem"

 

配置flannel自动启动脚本

vi /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=/app/kubernetes/cfg/flanneld

ExecStart=/app/kubernetes/bin/flanneld --ip-masq $FLANNEL_OPTIONS

ExecStartPost=/app/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env

Restart=on-failure

[Install]

WantedBy=multi-user.target

 

 

配置docker采用flannel网络

vi /usr/lib/systemd/system/docker.service

EnvironmentFile=/run/flannel/subnet.env

ExecStart=/usr/bin/dockerd \$DOCKER_NETWORK_OPTIONS

 图片1.png
 

 

启动服务

systemctl daemon-reload

systemctl  restart flanneld

systemctl  enable flanneld

systemctl  status flanneld

systemctl  restart  docker

systemctl  status  docker