<p>I'm seeking the answer regarding how to use the Kubernetes Python API to get cluster information (<code>kubectl get clusters</code>).</p>

<pre><code>~$ kubectl -n &lt;namespace&gt; get clusters
NAME         AGE
cluster-1   6d17h
cluster-2   6d17h
</code></pre>

<p>This one maybe help you, <a href="https://github.com/kubernetes-client/python/blob/d8f283e7483848647804eab345645106b6fb357d/examples/remote_cluster.py#L24" rel="nofollow noreferrer">at</a></p>
<pre><code>from pick import pick  # install pick using `pip install pick`

from kubernetes import client, config
from kubernetes.client import configuration


def main():
    contexts, active_context = config.list_kube_config_contexts()
    if not contexts:
        print(&quot;Cannot find any context in kube-config file.&quot;)
        return
    contexts = [context['name'] for context in contexts]
    active_index = contexts.index(active_context['name'])
    cluster1, first_index = pick(contexts, title=&quot;Pick the first context&quot;,
                                 default_index=active_index)
    cluster2, _ = pick(contexts, title=&quot;Pick the second context&quot;,
                       default_index=first_index)

    client1 = client.CoreV1Api(
        api_client=config.new_client_from_config(context=cluster1))
    client2 = client.CoreV1Api(
        api_client=config.new_client_from_config(context=cluster2))

    print(&quot;\nList of pods on %s:&quot; % cluster1)
    for i in client1.list_pod_for_all_namespaces().items:
        print(&quot;%s\t%s\t%s&quot; %
              (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

    print(&quot;\n\nList of pods on %s:&quot; % cluster2)
    for i in client2.list_pod_for_all_namespaces().items:
        print(&quot;%s\t%s\t%s&quot; %
              (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
</code></pre>
