<p>I have 2 kubernetes cluster in 2 region</p>
<p>2 kubeconfig file are <strong>kube1.kubeconfig</strong> and <strong>kube2.kubeconfig</strong></p>
<p>I'm using python to call to kubernetes cluster using kubernetes-client python</p>
<p>I see it will load the config from the env <strong>KUBECONFIG</strong></p>
<p>but my program need to push API to 2 different cluster</p>
<p>So are there anyway to solve that problems:</p>
<p>Code for examples:</p>
<pre class="lang-py prettyprint-override"><code>if &lt;condiation a&gt;:
  (load kube1.kubeconfig)
  (process my code)
elif &lt;condition b&gt;:
  (load kube2.kubeconfig)
  (process my code)
</code></pre>

<p>With <code>kubectl</code> the usual way is to merge all <code>kubeconfig</code> files into one <code>kubeconfig</code> files and then use the context API to switch between contexts/clusters <code>kubectl config use-context my-context-1</code> or <code>kubectl config use-context my-context-2</code>. Looking at <a href="https://github.com/kubernetes-client/python/" rel="nofollow noreferrer">python kubernetes-client</a> it looks like you can do the same:</p>
<ul>
<li>To merge <code>kubeconfig</code> files you can have a look at <a href="https://stackoverflow.com/questions/46184125/how-to-merge-kubectl-config-file-with-kube-config">How to merge kubectl config file with ~/.kube/config?</a>.</li>
<li>To change context with <a href="https://github.com/kubernetes-client/python/" rel="nofollow noreferrer">python kubernetes-client</a> you can have a look at <a href="https://github.com/kubernetes-client/python/blob/ceaf188498bd43577b1bec72cc4e839be2379632/examples/pick_kube_config_context.py#L26" rel="nofollow noreferrer">this example</a>.</li>
</ul>
