1. 设置KUBECONFIG环境变量

    以下假设有两个配置kubeconfig。两个集群的contexts[i].context.nameclusters[i].name不要一样。

     ```bash
     vi /etc/profile
     # 如果是放在root用户,建议将${HOME}换成/root
     export KUBECONFIG=${HOME}/.kube/config:${HOME}/.kube/config-sz
     ```
    
  2. 通过kubectl config view --flatten自动合并

    1
    
    kubectl config view --flatten
    
  3. 使用

    虽然有点坑,总算解决了燃眉之急。

    1
    2
    
    # 指定context与kubeconfig
    kubectl --context sz --kubeconfig=~/.kube/config-sz get nodes
    

或者更简单点的方法

1
kubectl --kubeconfig=k8s-config get nodes