A, Flannel generate a certificate
1. Create Flannel generate a certificate file
[root@linux-node1 ~]# vim flanneld-csr.json { "CN": "flanneld", "hosts": [], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "BeiJing", "L": "BeiJing", "O": "k8s", "OU": "System" } ] }
2. Generate certificate
[root@linux-node1 ~]# cfssl gencert -ca=/opt/kubernetes/ssl/ca.pem \ -ca-key=/opt/kubernetes/ssl/ca-key.pem \ -config=/opt/kubernetes/ssl/ca-config.json \ -profile=kubernetes flanneld-csr.json | cfssljson -bare flanneld
3. distribution certificate
[root@linux-node1 ~]# cp flanneld*.pem /opt/kubernetes/ssl/ [root@linux-node1 ~]# scp flanneld*.pem 192.168.56.12:/opt/kubernetes/ssl/ [root@linux-node1 ~]# scp flanneld*.pem 192.168.56.13:/opt/kubernetes/ssl/
Two, Flannel installation
1. Download Flannel package
[Linux-node1 the root @ ~] # CD / usr / local / the src # wget HTTPS: // github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar. GZ [the root @ Linux the src-node1] # zxf flannel the tar-V0. 10.0 -linux- amd64.tar.gz [the root @ Linux -node1 the src] CP # flanneld mk-docker-opts.sh / opt / Kubernetes / bin / copy to Linux - node2 node [@ Linux the root -node1 the src] flanneld mk-docker-opts.sh SCP # 192.168 . 56.12 : / opt / Kubernetes / bin / [the root @ Linux -node1 the src] MK-docker- flanneld SCP # opts.sh 192.168 . 56.13 : / opt / Kubernetes / bin / copy corresponds to the script/ Opt / Kubernetes / Bin eyes录下. [Root Atto Linux -Node1 ~] # Cd / Usr / Local / Src / Kubernetes / Cluster / Centos / Node / Bin / [Root Atto Linux -Node1 Bin] # Cp Remove-docker0.Sh / Opt / Kubernetes / Bin / [ Atto Linux Root -Node1 Bin] # Scp Remove-docker0.Sh 192.168 . 56.12 : / Opt / Kubernetes / Bin / [Root Atto Linux -Node1 Bin] # Scp Remove-docker0.Sh 192.168 . 56.13 : / Opt / Kubernetes / Bin /
2. Configure Flannel
[root@linux-node1 ~]# vim /opt/kubernetes/cfg/flannel FLANNEL_ETCD="-etcd-endpoints=https://192.168.56.11:2379,https://192.168.56.12:2379,https://192.168.56.13:2379" FLANNEL_ETCD_KEY="-etcd-prefix=/kubernetes/network" FLANNEL_ETCD_CAFILE="--etcd-cafile=/opt/kubernetes/ssl/ca.pem" FLANNEL_ETCD_CERTFILE="--etcd-certfile=/opt/kubernetes/ssl/flanneld.pem" FLANNEL_ETCD_KEYFILE="--etcd-keyfile=/opt/kubernetes/ssl/flanneld-key.pem" 复制配置到其它节点上 [root@linux-node1 ~] # scp / opt / kubernetes / CFG / flannel 192,168 . 56.12 : / opt / kubernetes / CFG / [root @ linux -node1 ~] # scp / opt / kubernetes / CFG / flannel 192,168 . 56.13 : / opt / kubernetes / CFG /
3. Set Flannel System Services
[root@linux-node1 ~]# vim /usr/lib/systemd/system/flannel.service [Unit] Description=Flanneld overlay address etcd agent After=network.target Before=docker.service [Service] EnvironmentFile=-/opt/kubernetes/cfg/flannel ExecStartPre=/opt/kubernetes/bin/remove-docker0.sh ExecStart=/opt/kubernetes/bin/flanneld ${FLANNEL_ETCD} ${FLANNEL_ETCD_KEY} ${FLANNEL_ETCD_CAFILE} ${FLANNEL_ETCD_CERTFILE} ${FLANNEL_ETCD_KEYFILE} ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -d /run/flannel/docker Type=notify [Install] WantedBy=multi-user.target RequiredBy=docker.service
4, replicated to other nodes
# scp /usr/lib/systemd/system/flannel.service 192.168.56.12:/usr/lib/systemd/system/ # scp /usr/lib/systemd/system/flannel.service 192.168.56.13:/usr/lib/systemd/system/
Three, Flannel CNI integration
1, download the plug-CNI
https: // github.com/containernetworking/plugins/releases wget https: // github.com/containernetworking/plugins/releases/download/v0.7.1/cni-plugins-amd64-v0.7.1.tgz [Linux-root @ node1 ~] # mkdir / opt / kubernetes / bin / cm [root @ linux -node1 src] # tar zxf CNI-plugins-amd64-V0. 7.1 .tgz -C / opt / kubernetes / bin / cm # scp -r / opt / kubernetes / bin / cm / * 192.168.56.12:/opt/kubernetes/bin/cni/ # scp -r / opt / kubernetes / bin / cm / * 192.168.56.13:/opt/kubernetes/bin/cni/
2, create the key Etcd
/opt/kubernetes/bin/etcdctl --ca-file /opt/kubernetes/ssl/ca.pem --cert-file /opt/kubernetes/ssl/flanneld.pem --key-file /opt/kubernetes/ssl/flanneld-key.pem \ --no-sync -C https://192.168.56.11:2379,https://192.168.56.12:2379,https://192.168.56.13:2379 \ mk /kubernetes/network/config '{ "Network": "10.2.0.0/16", "Backend": { "Type": "vxlan", "VNI": 1 }}' >/dev/null 2>&1
3, start flannel
[root@linux-node1 ~]# systemctl daemon-reload [root@linux-node1 ~]# systemctl enable flannel [root@linux-node1 ~]# chmod +x /opt/kubernetes/bin/* [root@linux-node1 ~]# systemctl start flannel
4, check the service status
[root@linux-node1 ~]# systemctl status flannel
Fourth, the configuration Docker use Flannel
1, modify the file docker.service
[root@linux-node1 ~]# vim /usr/lib/systemd/system/docker.service [Unit] #在Unit下面修改After和增加Requires After=network-online.target firewalld.service flannel.service Wants=network-online.target Requires=flannel.service [Service] #增加EnvironmentFile=-/run/flannel/docker Type=notify EnvironmentFile=-/run/flannel/docker ExecStart=/usr/bin/dockerd $DOCKER_OPTS
2, replicated to other nodes
# scp /usr/lib/systemd/system/docker.service 192.168.56.12:/usr/lib/systemd/system/ # scp /usr/lib/systemd/system/docker.service 192.168.56.13:/usr/lib/systemd/system/
3, restart docker
[root@linux-node1 ~]# systemctl daemon-reload
[root@linux-node1 ~]# systemctl restart docker