Python examples for fetching pod details using Azure AKS SDK and kubernetes python

Rajesh Swarnkar 846 Reputation points


I am trying to fetch the the pods CPU and and Memory Limits details using Python SDK for an Azure Kubernetes Cluster (AKS Cluster). Any Example would be very helpful.

I already have setup Python packages: azure-identity, azure-common, azure-mgmt-hybridkubernetes, azure-mgmt-kubernetesconfiguration .

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,781 questions
0 comments No comments
{count} votes

Accepted answer
  1. Akram Kathimi 1,041 Reputation points Microsoft Employee

    Hi @Rajesh Swarnkar ,

    The Azure Python SDK, is used to manage the cluster. For fetching the pods' info you would need to use the Kubernetes package.

    For example:

    from kubernetes import client, config
    v1 = client.CoreV1Api()
    pods = v1.list_pod_for_all_namespaces().items
    # Get the CPU and memory limits for each pod
    for pod in pods:
        print(f'Pod name: {}')
        for container in pod.spec.containers:
            print(f'\tContainer name: {}')
            if container.resources.limits:
                if 'cpu' in container.resources.limits:
                    print(f'\tCPU limit: {container.resources.limits["cpu"]}')
                    print("\tNo cpu resource limits defined")
                if 'memory' in container.resources.limits:
                    print(f'\tMemory limit: {container.resources.limits["memory"]}')
                    print("\tNo memory resource limits defined")
               print("\tNo resource limits defined") 

    I hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful