<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>

Lê Minh Quân
<p>You can create separate clients from different <code>kubeconfig</code>s using <code>new_client_from_config_dict</code> function. This gives you 2 isolated clients without having to load the config globally:</p>
<pre class="lang-py prettyprint-override"><code>def make_k8s_client(kubeconfig: dict) -&gt; kubernetes.client.CoreV1Api:
    api_client = kubernetes.config.new_client_from_config_dict(kubeconfig)
    return kubernetes.client.CoreV1Api(api_client)
    
with open('kubeconfig.yaml') as f:
    kubeconfig = yaml.safe_load(f)

k8s_1 = make_k8s_client(kubeconfig)

# a different config

with open('kubeconfig2.yaml') as f:
    kubeconfig2 = yaml.load(f)

k8s_2 = make_k8s_client(kubeconfig2)
</code></pre>
