I would like to merge multiple kubeconfig files into one config file.I am using Windows 10 and PS for commnand line. I have 3 config files in $HOME\.kube\config
directory and I set a KUBECONFIG environment variable with C:\Users\Username\.kube.\config
I tried below command as below but I received an error says:
KUBECONFIG=$HOME.kube\config:$HOME.kube\c1.kubeconfig\$HOME.kube\c2.kubeconfig : The module 'KUBECONFIG=$HOME' could not be loaded. For more information, run 'Import-Module KUBECONFIG=$HOME'. At line:1 char:1 + KUBECONFIG=$HOME.kube\config:$HOME.kube\c1.kubeconfig\$HOME.k ... +
~ + CategoryInfo : ObjectNotFound: (KUBECONFIG=$HOM...2.kubeconfig:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoLoadModule
KUBECONFIG=$HOME\.kube\config:$HOME\.kube\c1.kubeconfig\$HOME\.kube\c2.kubeconfig kubectl config view --merge --flatten $HOME\.kube\merged_kubeconfig
My Folder structure as below.
.kube
-c1.kubeconfig
-c2.kubeconfig
-config
Resolved issue with merging kubeconfig files using below command for Windows
$Env:KUBECONFIG=("$HOME\.kube\config;$HOME\.kube\c1.kubeconfig;$HOME\.kube\c2.kubeconfig"); kubectl config view --merge --flatten | Out-File "C:\Users\SU\tmp\config"
You will need to update the command to use semicolon as a delimiter for Windows
like Note the usage of ;
$Env:KUBECONFIG=("$HOME\.kube\config;$HOME\.kube\c1.kubeconfig")
Test by echo to check what you get updated
echo $Env:KUBECONFIG
C:\Users\DT\.kube\config;C:\Users\DT\.kube\c1.kubeconfig