In the previous section we deployed ETCD, and this section installs and configures flannel. Build Flannel
Flannel do not have a ready-made executable file available, you must build it yourself, the most reliable way is to build in the Docker container. But for build Docker mirror hosting in Gcr.io, domestic may not be directly accessible, for the convenience of everyone, I put it mirror to the Docker hub, the construction steps are as follows:
Download and rename the image.
Docker Pull Cloudman6/kube-cross:v1.6.2-2
Docker tag Cloudman6/kube-cross:v1.6.2-2 gcr.io/google_containers/kube-cross:v1.6.2-2
Download Flannel source code.
git clone https://github.com/coreos/flannel.git
Start building.
CD Flannel
Make Dist/flanneld-amd64
Copy the Flanneld execution files to host1 and Host2.
SCP Dist/flanneld-amd64 192.168.56.104:/usr/local/bin/flanneld
SCP dist/flanneld-amd64 192.168.56.105:/usr/local/bin/flanneld to save configuration information for flannel network to ETCD
The configuration information is first written to the file Flannel-config.json, which reads:
{
"Network": "10.2.0.0/16",
"Subnetlen": 24,
"Backend": {
' Type ': ' Vxlan '
}
}
Network defines the IP pool for this network as 10.2.0.0/16.
Subnetlen Specifies that each host is assigned a subnet size of 24 bits, that is, 10.2.x.0/24.
Backend for Vxlan, that is, between the host through the Vxlan communication, we will also discuss the HOST-GW later.
Save Configuration to Etcd:
Etcdctl--endpoints=192.168.56.101:2379 Set/docker-test/network/config < Flannel-config.json
/docker-test/network/config is the key of this ETCD data item, and its value is Flannel-config.json content. The key can be specified arbitrarily, and this key will be used as a startup parameter for Flanneld. Performing Etcdctl get ensures that the settings are successful.
Start Flannel
Execute the following command on Host1 and host2:
Flanneld-etcd-endpoints=http://192.168.56.101:2379-iface=enp0s8-etcd-prefix=/docker-test/network
-etcd-endpoints specifies the Etcd URL.
-IFACE specifies the interface used for data transfer between hosts.
-ETCD-PREFIX specifies the key that ETCD stores flannel network configuration information.
The output of the host1 is as follows:
①ENP0S8 is chosen as the interface to communicate with an external host.
② identifies flannel network pool 10.2.0.0/16.
The subnet assigned by ③ is 10.2.40.0/24.
After the Flanneld starts, some changes will occur in the HOST1 internal network:
A new interface FLANNEL.1 is created and configured with the first IP 10.2.40.0 on subnet.
Host1 adds a route: packets with the destination address flannel network 10.2.0.0/16 are forwarded by FLANNEL.1.
Host2 output is similar, the main difference is host2 subnet for 10.2.17.0/24:
The current environment network topology is shown in the figure:
The flannel is ready, and the next section shows how to use the Flannel network in Docker.