Get specific attribute from kubectl describe node

3/4/2022

I am trying to get the maximum capacity of pod per node. I am running kubectl describe node nodename and trying to grep the pods limit in capacity section. Any help would be appreciated. The output is like this.

Capacity:
  attachable-volumes-azure-disk:  8
  cpu:                            4
  ephemeral-storage:              129900528Ki
  hugepages-1Gi:                  0
  hugepages-2Mi:                  0
  memory:                         16393308Ki
  pods:                           110
-- user16133873
azure-aks
kubectl
kubernetes

2 Answers

3/4/2022

try the below command

kubectl describe no node01 | sed -n '/Capacity/,/pods/p' | grep -i pods | awk '{print $2}'
-- P Ekambaram
Source: StackOverflow

3/4/2022

if you want to use just native ooptions of kubectl command

kubectl get nodes <nodename> -o jsonpath='{.status.capacity.pods}{"\n"}'

If you dont need trailing newline character after the output:

kubectl get nodes <nodename> -o jsonpath='{.status.capacity.pods}'

-- confused genius
Source: StackOverflow