Configuring the Kubernetes Cluster
Configure the Kubernetes cluster on the management and compute nodes.
Configuring the Management Node
- Initialize the management node.
kubeadm init --image-repository registry.aliyuncs.com/google_containers --apiserver-advertise-address=192.168.114.202 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --kubernetes-version=v1.20.6
- image-repository: address of the container image repository.
- apiserver-advertise-address: IP address of the API server. It must be an accessible intranet IP address. Set this parameter based on your requirements.
- pod-network-cidr: IP address range of the pod network.
- service-cidr: IP address range of the service network.
- kubernetes-version: Kubernetes version.
Figure 1 shows the information displayed after the management node is initialized successfully. The information in the yellow box indicates the command for configuring the cluster on the management node. The information in the red box indicates the token command for adding the compute nodes to the cluster. Save the command. This token command can be used to add the compute nodes to the cluster within 24 hours.
- The token for adding a compute node to the cluster is randomly generated. You need to use the corresponding command when creating a cluster.
- The default validity period of a token is 24 hours. If the token times out, you can run the following command on the management node in the Kubernetes cluster to generate a new token.
1kubeadm token create --print-join-command
- Set .kube/config.
mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
- Deploy the flannel component.
- Download the kube-flannel.yml file from the following link and save it to the target path, for example, /home.
https://github.com/flannel-io/flannel/blob/master/Documentation/kube-flannel.yml
- Deploy the flannel component.
kubectl apply -f kube-flannel.yml
- Download the kube-flannel.yml file from the following link and save it to the target path, for example, /home.
Configuring a Compute Node
- On a compute node, run the following command to add the compute node to the cluster:
kubeadm join 192.168.114.202:6443 --token a9020j.vnfgqk7n30p5d9z0 --discovery-token-ca-cert-hash sha256: c465651177b41c545fe20f8dc052b9661a8375afdeac7e7ecf52029fc66a506a
- This command is the token command displayed after the management node is initialized.
- If the token times out, run the following command on the Kubernetes management node to generate a new token:
kubeadm token create --print-join-command
- Wait for 1 minute and run the following command on the management node to check the cluster status:
kubectl get nodes
The compute node has been added to the cluster. An example of the expected result:

Parent topic: Deploying the Kubernetes Cluster
