powershellkuberneteskubectlkubeconfig

How to set multiple kubeconfigs using powershell


The kubectl documentation says, we should use : to separate paths to multiple kubeconfig files, but it does not work in powershell:

> $env:KUBECONFIG="C:\Users\me\.kube\staging-config:C:\Users\me\.kube\demo-k8s-config"
> kubectl config get-contexts
error: error loading config file "C:\Users\me\.kube\staging-config:C:\Users\me\.kube\demo-k8s-config": open C:\Users\dturanme.kube\staging-config:C:\Users\me\.kube\demo-k8s-config: The filename, directory name, or volume label syntax is incorrect.

I've tried with newline separator as well.


Solution

  • You are correct ( : ) does not work in powershell to separate paths to multiple kubeconfig files instead it uses semicolon ( ; ) to separate paths.

    For Example:

    $env:KUBECONFIG="C:\\Users\\me.kube\\staging-config;C:\\Users\\me.kube\\demo-k8s-config"
    

    In Powershell, the colon ( : ) is used to separate the drive letter from the rest of the path.

    Refer to the official kubernetes document on Set the KUBECONFIG environment variable for more information.