Kubectl is a command line tool provided by Kubernetes for performing operations on clusters. It uses kubeconfig as a configuration file (the default path is ~/.kube/config
) to configure the information of multiple clusters, and manage and operate multiple clusters.
To manage and operate the TKE or TKE Serverless cluster through Kubectl, you need to enable the APIServer's public or private network access on the cluster basic information page to obtain kubeconfig (cluster access credentials). If you need to use kubectl to manage multiple clusters, generally you need to extract the contents of each field in kubeconfig and merge them into the kubeconfig file of the device where kubectl locates. This method is complicated and may easily cause an error.
Through the kubecm tool, you can merge multiple cluster access credentials into kubeconfig more simply and efficiently. This document describes how to use kubecm to efficiently manage the kubeconfig of multiple clusters.
Install kubecm on the device used for managing multiple clusters.
After creating a cluster, you need to follow the steps below to obtain access credential for the cluster:
This document takes the cluster access credential cls-l6whmzi3-config
as an example. Run the following command to use kubecm to add the access credential to kubeconfig (-n
means you can specify the context name):
kubecm add -f cls-l6whmzi3-config -n cd -c
Run the following kubecm ls
command to view the cluster list in kubeconfig (the asterisk identifies the cluster under operation):
$ kubecm ls
+------------+------------+-----------------------+--------------------+-----------------------------------+-------------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+============+=======================+====================+===================================+===================+
| * | cd | cluster-chh6kgf9d9 | user-chh6kgf9d9 | https://cls-l6whmzi3.ccs.tence | default |
| | | | | nt-cloud.com | |
+------------+------------+-----------------------+--------------------+-----------------------------------+-------------------+
| | bj | cluster-6qaua96n | user-6qaua96n | https://cls-6qaua96n.ccs.tence | kube-system |
| | | | | nt-cloud.com | |
+------------+------------+-----------------------+--------------------+-----------------------------------+-------------------+
Run the following kubecm switch
command to interactively switch to another cluster:
Run the following kubecm delete
command to remove a cluster:
$ kubecm delete bj
Context Delete:「bj」
「/Users/roc/.kube/config」 write successful!
+------------+---------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+=========+=======================+====================+===================================+==============+
| | cd | cluster-chh6kgf9d9 | user-chh6kgf9d9 | https://cls-l6whmzi3.ccs.tence | default |
| | | | | nt-cloud.com | |
+------------+---------+-----------------------+--------------------+-----------------------------------+--------------+
Apakah halaman ini membantu?