ᕕ( ᐛ )ᕗ Jimyag's Blog

k8s 合并多个 kube config 文件

先备份已有的 kubeconfig 文件

cp ~/.kube/config1 ~/.kube/config.bak1
cp ~/.kube/config2 ~/.kube/config.bak2

通过此环境变量来指定多个 kubeconfig

export KUBECONFIG=~/.kube/config1:~/.kube/config2

合并 kubeconfig 文件

kubectl config view --flatten > ~/.kube/config.new

测试 kubeconfig 文件,展示所有的 context

KUBECONFIG=~/.kube/config  kubectl config get-contexts
CURRENT   NAME                              CLUSTER          AUTHINFO           NAMESPACE
*         kubernetes-admin@local1           local1           kubernetes-admin
          kubernetes-admin@local2           local2           kubernetes-admin

#k8s