This topic describes how to merge kubeconfig files of multiple clusters and switch between different contexts.

You can obtain the content of the kubeconfig file for a cluster, which indicates the access credentials of the current user for the cluster, on the cluster details page of the Container Service console. You can also call an openapi to obtain the content of the kubeconfig file. If your Alibaba Cloud account can access multiple clusters, you can run the following command to merge kubeconfig files of these clusters to one credential file:
KUBECONFIG=file1:file2:file3 kubectl config view --merge --flatten > ~/.kube/all-config
export KUBECONFIG=~/.kube/all-config
  • Run the following command to view all available contexts:
    kubectl config get-contexts
  • Run the following command to view the help information of the kubeconfig file:
    kubectl config --help
  • Run the following command to change the context:
    kubectl config use-context {your-contexts}
For more information about kubeconfig files, see the official document.