Instructions for using Flannel in kubernetes cluster

Instructions for using Flannel in kubernetes cluster

Tong Fei 360 Cloud Computing

Heroine declaration

As a very representative product in the container cloud, docker has received very extensive attention in recent years, and how to manage a container cloud like docker is also a very headache. This article mainly uses the flannel component in the k8s cluster management The analysis and discussion of docker cluster will provide a little help for everyone to understand docker cluster management.
PS: Rich first-line technology and diversified forms of expression are all in the "HULK first-line technology talk", please pay attention!

The k8s cluster installation and configuration etcd will configure a network segment for the installed k8s cluster. This network segment is the IP address segment that can be used by the containers in the entire cluster. For example, when we install etcd, we execute etcdctl set to set a key-value The key-value pair specifies the network segment range of this cluster, but how to ensure that the ip address of the container in each minion node is unique, you need flannel to help. Flannel does this twice for each minion node based on this network segment of the cluster Division of subnets. Next, we will analyze how flannel and etcd work together to accomplish this work.
When installing and configuring the k8s cluster, you need to install flannel for each minion node. We mainly analyze how flannel works from the configuration file to complete the secondary division of the cluster subnet.
The flannel configuration file flanneld is as follows:


# Flanneld configuration options
# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD="http://192.168.163.152:2379"
# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_KEY="/coreos.com/network"
# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

In the configuration file, we see that two parameters are specified. One is FLANNEL_ETCD. This value specifies the address and port where we installed the etcd server. You can use the netstat command to see the connection status of the minion side. You can see the minion side and the etcd server etcd This setting allows the flannel of the minion node to communicate with the etcd of the server:
Instructions for using Flannel in kubernetes cluster
the link status of the flannel in the minion node

The second value FLANNEL_ETCD_KEY is a specified key. We executed a command when installing the etcd server:


etcdctl -C 192.168.163.148:2379 set /coreos.com/network/config '{ "Network": "192.168.0.0/16" }'

This value is very important. The value corresponding to this key is the startup parameter range set for each of our minion machines for docker. First look at a picture, this picture is the startup parameters of the minion machine docker
Instructions for using Flannel in kubernetes cluster
minion1 docker startup parameters
Instructions for using Flannel in kubernetes cluster
minion2 docker startup parameters

It should be noted that the --bip=192.168.102.1/24 parameter in the docker startup parameters. The function of flannel is to modify this parameter, which is equivalent to dividing the subnet for the docker of each minion host. Then check through ifconfig and you can see the picture:
Instructions for using Flannel in kubernetes cluster
minion2's network port information

There is an extra docker virtual network card, so when we install kubernetes, if we find that the network segment of the docker0 network card is not in the FLANNEL_ETCD_KEY after we install docker, it will cause docker to fail to start. Executing kubectl get node on the kubernetes node will display the node node not ready.

In summary

As a component provided by coreos to k8s, flannel obtains information about the entire cluster network segment by communicating with etcd during operation and performs secondary allocation of subnets, so that each minion node can have a unique subnet segment, and then Ensure that the docker containers running in the entire k8s cluster can obtain a unique IP address.

Guess you like

Origin blog.51cto.com/15127564/2668387