<p>I need to use <a href="https://github.com/Azure/azure-sdk-for-python" rel="nofollow noreferrer">Azure Python SDK</a> and <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">Kubernetes Python Client</a> to list the Pods CPU limits for a cluster running in AKS.</p>
<p>Although its straight forward using CLI/PowerShell but I need to use Python exclusively.
Must not use <a href="https://stackoverflow.com/questions/53535855/how-to-get-kubectl-configuration-from-azure-aks-with-python">subprocess calls</a>.</p>
<p>Here is snippet that gets <code>KubeConfig</code> object after authentication with Azure:</p>
<pre class="lang-py prettyprint-override"><code>from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient

credential = DefaultAzureCredential(exclude_cli_credential=True)
subscription_id = &quot;XXX&quot;
resource_group_name= 'MY-SUB'
cluster_name = &quot;my-aks-clustername&quot; 
container_service_client = ContainerServiceClient(credential, subscription_id)

kubeconfig = container_service_client.managed_clusters. \
list_cluster_user_credentials(resource_group_name, cluster_name). \
kubeconfigs[0]
</code></pre>
<p>But I am unsure how to put this to be used by K8s Python client:</p>
<pre class="lang-py prettyprint-override"><code>from kubernetes import client, config
config.load_kube_config() ## How to pass? 

v1 = client.CoreV1Api()
print(&quot;Listing pods with their IPs:&quot;)
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print(&quot;%s\t%s\t%s&quot; % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
</code></pre>

<p>You can use the <code>config.load_kube_config</code> method and pass in the kubeconfig object you obtained earlier as a parameter. The method accepts a <code>config_file</code> parameter, which can be a file object, a file-like object, or a string file path.</p>
<p>Since <strong>kubeconfig</strong> is a string, you can pass it as a string file path, like so:</p>
<pre><code>from kubernetes import client, config

# Pass the kubeconfig string as a file path
config.load_kube_config(config_file=kubeconfig)

v1 = client.CoreV1Api()
print(&quot;Listing pods with their IPs:&quot;)
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print(&quot;%s\t%s\t%s&quot; % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
</code></pre>
