<p>I am a newbie in kubernetes clustering therefore it might be a simple question. So I installed minikube on my local machine and it creates a config file into  $HOME/.kube/config. When I run <em><code>kubectl config view</code></em> command on Power Shell I can able to view the credentials. I already set a KUBECONFIG env variable and path is <code>$HOME/.kube/config.</code></p>

<p>So the question is, in our company, we have an onpremise kubernetes cluster and I had a 2 different kubeconfig files per cluster. (one for stage one for production). What is the best way to define these kubeconfig files as an env variable to access these clusters?</p>

<p>What I tried, I put these files into <code>$HOME/.kube</code> directory and at the present I have three files such as <em>config , c1.kubeconfig,c2.kubeconfig</em> Then I updated my environment variable like 
<code>$HOME/.kube/config:$HOME/.kube/c1.kubeconfig:$HOME/.kube/c2.kubeconfig</code>. But this way I can not able to access c1 or c2 cluster.</p>

semural
<p>When you use KUBECONFIG environment variable you can only point it to one kubeconfig file and not to a series of kubeconfig files. You need to merge all the individual kubeconfig files into one kubeconfig file and store it as $HOME/.kube/config and then select a cluster using context flag of kubectl.</p>

<pre><code>cp $HOME/.kube/config $HOME/.kube/config.backup.$(date +%Y-%m-%d.%H:%M:%S)
KUBECONFIG=$HOME/.kube/config:file2:file3 kubectl config view --merge --flatten &gt; \
~/.kube/merged_kubeconfig &amp;&amp; mv ~/.kube/merged_kubeconfig ~/.kube/config
kubectl get pods --context=cluster-1
kubectl get pods --context=cluster-2
</code></pre>

<p><a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#merging-kubeconfig-files" rel="nofollow noreferrer">official docs here</a></p>
