Kubernetes Installation and Configuration
Installing Kubernetes
Installation method 1 (recommended):
Refer to the Kubernetes official website to install Kubernetes.
- Install the kubectl, kubeadm, and kubelet tools of Kubernetes.
- Kubernetes versions 1.18.x to 1.25.x are supported. Kubernetes 1.19.x or later is recommended.
- kubeadm and kubelet need to be installed on all nodes, and kubectl needs to be installed only on the management node.
- Use kubeadm to create a Kubernetes cluster. For details about how to install kubeadm and create a Kubernetes cluster, see Creating a cluster with kubeadm on the Kubernetes official website.
If you encounter any problem during cluster initialization, see "Reference" > "FAQs" > "Faults During Installation" > "Kubernetes Initialization Failed" in MindCluster Cluster Scheduling Installation Guide.
Installation method 2:
Install Kubernetes by referring to the Alibaba image source. The following operations are performed on the management node. It is recommended that the software with the Arm architecture be used.
- Obtain the kubectl, kubeadm, and kubelet packages of Kubernetes. The following uses v1.25 as an example.
- Install kubectl, kubeadm, and kubelet by referring to the home page of the Alibaba Kubernetes image official website.
If information such as "No match for argument: socat" or "nothing provides socat needed by xxx" is output, the socat library is missing in the environment. Rectify this fault as follows. (The same command output will be displayed if other libraries, such as iptables and conntrak, are missing.)
Run the following command to install the missing library:
# CentOS yum install -y socat # Ubuntu apt-get install -y socat
- Run the following command to query the dependencies and images required for deploying Kubernetes, as shown in Figure 1.
kubeadm config images list
According to the query result, you need to run the docker pull command to install the dependencies and images in sequence. An example command is as follows:docker pull k8s.gcr.io/kube-apiserver:v1.23.0
- Run the following command to initialize the Kubernetes cluster. If information similar to Figure 2 is displayed, the initialization is successful.
kubeadm init
Then, execute the content displayed in Figure 2, as shown in the following:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Run the following command to check whether the statuses of default startup items are normal, as shown in Figure 3. If the statuses are Running, the items are normal.
kubectl get pods -A
Resetting Kubernetes Configurations
Run the following command to reset Kubernetes configurations. If information similar to Figure 4 is displayed, the Kubernetes configurations are successfully reset.
kubeadm reset
After the reset is successful, you need to manually delete the {$HOME}/.kube/config file to ensure that all Kubernetes configurations are deleted.
Adding Compute Nodes to a Kubernetes Cluster
If only one server is used in the cluster, you do not need to add compute nodes. In this case, skip the following steps.
The node to be added must meet the following requirements:
kubeadm and kubelet have been installed.
- On the management node, create a token and ca-cert code required for adding a new node to the cluster.The token and ca-cert code are valid for 24 hours. If they have expired, use the following commands to create new ones.
- Create a token.
kubeadm token create
- Create a ca-cert code.
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
- The preceding commands contain plaintext tokens. After the commands are executed, the tokens can be printed in historical operation query mode. As a result, sensitive information is exposed. You are advised to perform the following operations:
- Before running a sensitive command, temporarily disable the historical operation query function.
set +o history
- After the sensitive command operation is complete, restore the historical query function.
set -o history
- Before running a sensitive command, temporarily disable the historical operation query function.
- Create a token.
- Run the following command on the new node to add it to the cluster.
kubeadm join ip:port --token {token} \ -discovery-token-ca-cert-hash sha256:{ca-cert code}Parameters:- ip:port: IP address and port number of Kubernetes on the management node.
- --token: token for node adding.
- -discovery-token-ca-cert-hash: hash value of the certificate for adding the node to the cluster.
- Run the following command on the new node to query the host name.
hostname
If the host name conflicts with the name of another node in the cluster, modify the /etc/hostname file to change the host name.
- Run the kubectl get nodes -A command on the management node to view the node information. As shown in Figure 5, localhost.localdomain is the new node.
- Run the following command on the management node to add the accelerator=huawei-Ascend910 or accelerator=huawei-Ascend310x label to the new node based on the actual NPU type.
#kubectl label nodes {node_name} accelerator=huawei-Ascend910 kubectl label nodes localhost.localdomain accelerator=huawei-Ascend910 - Run the following command on the management node to check the accelerator=huawei-Ascend910 label added to the new node, as shown in Figure 6. If accelerator=huawei-Ascend910 is displayed, the operation is successful.
kubectl get nodes --show-labels





