Connecting to a Cluster

Last updated: 2020-02-24 18:19:48


Operation Scenarios

You can connect to a TKE cluster from a local client using kubectl, the Kubernetes command line tool.


Please install curl software.
Please select an appropriate way to obtain kubectl based on the OS type:

Replace "v1.8.13" in the command line with the kubectl version required by your business based on actual needs.

  • MacOS X
    Run the following command to obtain kubectl:
curl -LO
  • Linux
    Run the following command to obtain kubectl:
curl -LO
  • Windows
    Run the following command to obtain kubectl:
curl -LO


Install Kubectl tools

  1. Install kubectl as instructed in Installing and Setting up kubectl .

If you have already installed kubectl, ignore this step.
This step takes the Linux system as an example.

  1. Run the following command to add run permission.
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
  1. Run the following command to check the installation result.
kubectl version

If the output is similar to the following version information, the installation is successful.

Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:57:25Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

Configuring Kubeconfig

  1. Log in to the TKE console and click Clusters In the left sidebar.
  2. Click the ID/name Of the cluster to be connected to to go to the management page of the cluster.
  3. Select "basic Information" in Left sidebar, and you can view the Access address, public network / private network, Access status, Kubeconfig Access and credential content of the cluster in the "Cluster APIServer Information" module on the "basic Information" page.
  • Access address Cluster APIServer address Please note that this address does not support copying and pasting to the browser for Access.
  • Get Access Entry Please set it up according to the actual needs.
    • Public Network Access It is not enabled by default. Open the public network Access Cluster apiserver Open will be transferred to the public network. Please proceed with caution. . Source authorization needs to be configured. It is rejected by default. You can configure a single IP or CIDR of Open to Internet, which is strongly not recommended. All sources of Open to Internet.
    • Private network Access It is not enabled by default. When you enable private network and Access, you need to configure a subnet. If enabled successfully, the Assign IP address will be in the configured subnet.
  • Kubeconfig Access and credential of this cluster can be copied and downloaded.
  1. Configure the cluster credentials according to the actual situation.
    Before configuration, please determine whether the current Access client has been configured with any cluster of Access and credential:
    • No That is, ~/.kube/config The content of the file is empty. You can directly copy the acquired contents of Kubeconfig Access and credential and paste them into ~/.kube/config Medium. If the client does not have ~/.kube/config File, which you can create directly.
    • Yes You can download the acquired Kubeconfig to the specified location and execute the following command in turn to merge the config of multiple clusters.
KUBECONFIG=~/.kube/config:~/Downloads/cls-3jju4zdc-config kubectl config view --merge --flatten > ~/.kube/config
export KUBECONFIG=~/.kube/config
among, `~/Downloads/cls-3jju4zdc-config` For the file path of the Kubeconfig of this cluster, replace it with the actual path after downloading to the local server.

Access Kubernetes Cluster

  1. After completing the Kubeconfig configuration, execute the following command to view and switch the context to Access's cluster.
kubectl config get-contexts
kubectl config use-context cls-3jju4zdc-context-default
  1. Execute the following command to test whether the Access cluster is working.
kubectl get nodes

If you are unable to connect, please check whether the public network Access or private network Access Entry has been enabled, and make sure that the Access client is in the specified network environment.


Overview of kubectl CLI

Kubectl is a command line tool for Kubernetes cluster operations. This article covers kubectl syntax, common command operations, and provides common examples. For more information about each command, including all main commands and subcommands, see Kubectl reference documentation Or use the kubectl help Command to view detailed help, for kubectl installation instructions, see Install Kubectl tools .