Focus on cloud service provider activities
Notes on website operation and maintenance

Install the kubectl command line tool method Record the kubectl installation process

Kubectl is a command line interface used to run commands on the Kubernetes cluster and complete basic operations such as connecting to the k8s cluster, viewing resources, and deploying. Kubectl can manage the cluster itself and install and deploy container applications on the cluster. In this article, we will introduce the installation of kubectl command line tool method records.

1. Kubectl installation steps

Download Kubectl package

 wget  https://dl.k8s.io/v1.6.0/kubernetes-client-linux-amd64.tar.gz tar -xzvf kubernetes-client-linux-amd64.tar.gz cp kubernetes/client/bin/kube* /usr/bin/ chmod a+x /usr/bin/kube*

If you want to download a specified version, you can replace this part of the command with the specified version number: $(curl - L - s https://dl.k8s.io/release/stable.txt )。 For example, to download v1.23.0 in Linux, enter:

 curl -LO  https://dl.k8s.io/release/v1.23.0/bin/linux/amd64/kubectl

The installation of kubectl will then begin.

 sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Even without root permission of the target system, you can still install kubectl into the directory~/. local/bin:

 chmod +x kubectl mkdir -p ~/.local/bin/kubectl mv ./ kubectl ~/.local/bin/kubectl #Then add~/. local/bin/kubectl to $PATH

Finally, run the following command to test that the installed kubectl version is the latest.

 kubectl version –client

2. Create kubectl kubeconfig file

 export KUBE_APISERVER=" https://172.20.0.113:6443 " #Set cluster parameters kubectl config set-cluster kubernetes \ --certificate-authority=/etc/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=${KUBE_APISERVER} #Set client authentication parameters kubectl config set-credentials admin \ --client-certificate=/etc/kubernetes/ssl/admin.pem \ --embed-certs=true \ --client-key=/etc/kubernetes/ssl/admin-key.pem #Set context parameters kubectl config set-context kubernetes \ --cluster=kubernetes \ --user=admin #Set Default Context kubectl config use-context kubernetes

The value of the OU field of admin.pem certificate is system: masters. The predefined RoleBinding cluster admin of kube apiserver binds the Group system: masters with the Role cluster admin. The Role grants the permission to call the relevant API of kube apiserver;

The generated kubeconfig is saved to the~/. kube/config file.

3. Verify the executable file

Download the kubectl checksum file:

 curl -LO " https://dl.k8s.io/ $(curl -L -s  https://dl.k8s.io/release/stable.txt )/bin/linux/amd64/kubectl.sha256"

Verify the executable file of kubectl based on the checksum file:

 echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

When the verification passes, the output is:

 kubectl: OK

When the verification fails, sha256 will exit with a non-zero value and print the following output:

 kubectl: FAILED sha256sum: WARNING: 1 computed checksum did NOT match

Note: The downloaded kubectl and checksum file versions must be the same.

Install kubectl

 sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Note: Even if you do not have root permission on the target system, you can still install kubectl into the directory~/. local/bin:

 chmod +x kubectl mkdir -p ~/.local/bin mv ./ kubectl ~/.local/bin/kubectl #Then attach~/. local/bin to $PATH

Perform tests to ensure that the version you installed is the latest:

 kubectl version --client

Or use the following command to view the version details:

 kubectl version --client --output=yaml
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Install the kubectl command line tool method Record the kubectl installation process


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge