This document describes how to connect a local client to an elastic cluster through kubectl, which is the Kubernetes command-line tool.
Replace
v1.14.5
in the following commands with the actual version of your kubectl.
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.5/bin/darwin/amd64/kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.5/bin/linux/amd64/kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.5/bin/windows/amd64/kubectl.exe
- If you have already installed kubectl, skip this step.
- This step uses the Linux OS as an example.
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version
If the output is similar to the following version information, the installation was successful.Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.5", GitCommit:"0e9fcb426b100a2aea5ed5c25b3d8cfbb01a8acf", GitTreeState:"clean", BuildDate:"2019-08-05T09:21:30Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"windows/amd64"}
This method can be used to perform a single operation on a cluster. This way, you do not have to save the certificate information of the TKE cluster to the server for a long period of time.
Request:
Parameters in the kubectl command are described as follows:
-s "Domain information" --username=Username --password=Password --certificate-authority=Certificate path
admin
.token
in the Cluster Credential window. You can obtain the token from Step 5.Cluster CA Certificate
in the Cluster Credential window. You can obtain the path from Step 5.Examples
Run the following command to obtain the node information of a cluster:
kubectl get node -s "https://xxx.xx.xx.xxx:443/" --username=admin --password=6666o9oIB2gHD88882quIfLMy6666 --certificate-authority=/etc/kubernetes/cluster-ca.crt
This method can be used to perform long-term operations on a cluster through kubectl. You only need to configure the configuration file once, and the configuration file remains effective until it is modified.
kubectl config set-credentials default-admin --username=admin --password=6666o9oIB2gHD88882quIfLMy6666
kubectl config set-cluster default-cluster --server=https://xxx.xx.xx.xxx:443/ --certificate-authority=/etc/kubernetes/cluster-ca.crt
kubectl config set-context default-system --cluster=default-cluster --user=default-admin
kubectl config use-context default-system
kubectl get namespaces
A message similar to the following is returned, indicating that the configuration was successful.NAME STATUS AGE
default Active 11d
kube-system Active 11d
You can run the following command to enable auto-complete for all commands that you enter in kubectl, so as to improve the usability of kubectl.
source <(kubectl completion bash)
Was this page helpful?