命令如下:
kubectl config
Available Commands:
current-context Displays the current-context
delete-cluster Delete the specified cluster from the kubeconfig
delete-context Delete the specified context from the kubeconfig
get-clusters Display clusters defined in the kubeconfig
get-contexts Describe one or many contexts
rename-context Renames a context from the kubeconfig file.
set Sets an individual value in a kubeconfig file
set-cluster Sets a cluster entry in kubeconfig
set-context Sets a context entry in kubeconfig
set-credentials Sets a user entry in kubeconfig
unset Unsets an individual value in a kubeconfig file
use-context Sets the current-context in a kubeconfig file
view Display merged kubeconfig settings or a specified kubeconfig file
Usage:
kubectl config SUBCOMMAND [options]
最重要的一点,在能切换多集群前,务必引入多集群的config文件。
比如有1-config、2-config两个文件在$HOME/.kube下,那么使用如下命令合并:
echo "export KUBECONFIG=$KUBECONFIG:$HOME/.kube/1-config:2-config" >> ~/.bash_profile
#需要立即生效使用如下命令
export KUBECONFIG=$KUBECONFIG:$HOME/.kube/1-config:2-config
引入后 kubectl config view 就能看到 两个集群的信息
使用kubectl config get-contexts 可以看到集群的上下文信息
使用kubectl config use-context 集群context name,就能选中要用的集群