kubectl is a command-line tool provided by Kubernetes, enabling you to manage cluster resources, view cluster status, deploy applications, and debug issues through the CLI. To access a CCE cluster using kubectl, you can use either of the following methods:
This section uses a CCE standard cluster as an example to describe how to access a CCE cluster using kubectl.
kubectl retrieves cluster information from a kubeconfig file and communicates with the Kubernetes API server. The kubeconfig file is the identity credential for kubectl to access the Kubernetes cluster. It contains the API server address, user authentication credentials, and other configuration details. With these details, kubectl can interact with the Kubernetes cluster to perform management tasks.
Figure 1 Using kubectl to access a cluster

In a cluster with an EIP bound, kube-apiserver will be exposed to the Internet and may be attacked. To resolve this issue, you can configure Advanced Anti-DDoS for the EIP of the node on which kube-apiserver runs or configure security group rules.
A kubeconfig file contains user authentication credentials. When you use this file to access a cluster, kubectl accesses the cluster based on the credentials and permissions specified in the file.
For details about user permissions, see Cluster Permissions (IAM-based) and Namespace Permissions (Kubernetes RBAC-based).
Before using kubectl to access a cluster, install kubectl on the client. Run the kubectl version command to check whether kubectl is installed. If it is installed, skip this step. This section uses Linux as an example to describe how to install and configure kubectl. For details, see Installing kubectl.
cd /homecurl -LO https://dl.k8s.io/release/v1.25.0/bin/linux/amd64/kubectl
chmod +x kubectlmv -f kubectl /usr/local/bin
kubectl version
If information similar to the following is displayed, kubectl has been installed:
Client Version: xxxKustomize Version: xxxServer Version: xxx
Obtain kubeconfig (the kubectl configuration file) from the cluster for access.
The kubeconfig file is stored on the client, and kubectl uses it to access and interact with the cluster.
vim kubeconfig.yaml
Copy the configuration file information obtained in 2 to kubeconfig.yaml and save the file.
cd /homemkdir -p $HOME/.kubemv -f ~/kubeconfig.yaml $HOME/.kube/config # Change kubeconfig.yamlkubeconfig.yaml to the file name.
kubectl config use-context internal
kubectl config use-context external
kubectl config use-context externalTLSVerify
For more details, see Two-Way Domain Name Trust.
kubectl cluster-info # Check the cluster information.
If the following information is displayed, the client can access the cluster using kubectl:
Kubernetes control plane is running at https://xx.xx.xx.xx:5443CoreDNS is running at https://xx.xx.xx.xx:5443/api/v1/namespaces/kube-system/services/coredns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Two-way domain name trust is a mutual authentication mechanism that verifies the identities of both the client and server. This mode enhances security between clusters and clients, preventing unauthorized access.
Figure 2 Two-way trust disabled for domain names

When you use kubectl to create or query Kubernetes resources, the following output is returned:
# kubectl get deploy Error from server (Forbidden): deployments.apps is forbidden: User "0c97ac3cb280f4d91fa7c0096739e1f8" cannot list resource "deployments" in API group "apps" in the namespace "default"
The cause is that the user does not have the permissions to operate the Kubernetes resources. For details about how to assign permissions, see Namespace Permissions (Kubernetes RBAC-based).
When you use kubectl to create or query Kubernetes resources, the following output is returned:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
The cause is that cluster authentication is not configured for the kubectl client. For details, see Step 2: Obtain the kubectl Configuration File (kubeconfig).