kuberneteskubectl

Kubernetes - display current pods vs. capacity with kubectl


Kubernetes dashboard is able to show "current running pods / pods capacity" per node. But when I try to get the same info with kubectl I have to run two commands:

kubectl describe node | grep -E (^Name:|^Non-terminated)

which lists "current running pod on node", and

kubectl get nodes -o=custom-columns=NAME:.metadata.name,CAPACITY:.status.capacity.pods

which shows the node's capacity

Does anyone know how I can get the output similar to below using one command only?

NAME     CURRENT   CAPACITY
node_1   7         15
node_2   8         15
node_3   15        15

Thanks in advance!


Solution

  • There is no one command for this.

    It is possible to write script to do that with combining those two commands.

    Note that using integer based metrics like number of pods can be very misleading as pods can vary in how much space and cpus they consume. You might use up cpus and memory before you reach node pod count capacity.

    You can check available resources with command: kubectl top nodes

    Node capacity

    The capacity of the node (number of cpus and amount of memory) is part of the node object. Normally, nodes register themselves and report their capacity when creating the node object. If you are doing manual node administration, then you need to set node capacity when adding a node.

    The Kubernetes scheduler ensures that there are enough resources for all the pods on a node. It checks that the sum of the requests of containers on the node is no greater than the node capacity. It includes all containers started by the kubelet, but not containers started directly by the container runtime nor any process running outside of the containers.

    P.S.

    On Debian the first command had to be slightly modified to work:

    kubectl describe node | grep -E "(^Name:|^Non-terminated)"