I have a kubernetes
cluster working perfectly fine. It has 5 worker nodes. I am using below command to get the status of pods.
kubectl get pod -o wide --namespace=machines
which shows below results
NAME READY STATUS RESTARTS AGE IP NODE
deployment-26hfn 0/4 ContainerCreating 0 5m <none> machine003
deployment-782mk 0/4 Pending 0 5m <none> machine001
deployment-7kcc7 0/4 Pending 0 5m <none> machine002
deployment-8fzqs 0/4 ContainerCreating 0 5m <none> machine004
deployment-zfzts 0/4 ContainerCreating 0 5m <none> machine005
As you can see, the above result is not in order from machine001
to machine 005
. Is it possible to print the output like below:
NAME READY STATUS RESTARTS AGE IP NODE
deployment-26hfn 0/4 Pending 0 5m <none> machine001
deployment-782mk 0/4 Pending 0 5m <none> machine002
deployment-7kcc7 0/4 ContainerCreating 0 5m <none> machine003
deployment-8fzqs 0/4 ContainerCreating 0 5m <none> machine004
deployment-zfzts 0/4 ContainerCreating 0 5m <none> machine005
By default, nodes have limit of 100 pods per node ( as mentioned by docs, but looks like in fact this limit is 110 pods per node). You can check pods limit for specific node, by running kubectl describe node node_name, which, among other info will return something like this:
A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane. A Node can have multiple pods, and the Kubernetes control plane automatically handles scheduling the pods across the Nodes in the cluster.
Here's an example of a pod that uses node affinity: This node affinity rule says the pod can only be placed on a node with a label whose key is kubernetes.io/e2e-az-name and whose value is either e2e-az1 or e2e-az2.
Note: The value of these labels is cloud provider specific and is not guaranteed to be reliable. For example, the value of kubernetes.io/hostname may be the same as the Node name in some environments and a different value in other environments. Adding labels to Node objects allows targeting pods to specific nodes or groups of nodes.
You can pipe the kubectl command output to sort:
kubectl get pods -o wide --namespace=machines | sort -k7
or to omit the first line
kubectl get pods -o wide --namespace=machines | sed -n '1!p' | sort -k7
Also, you should be able to do this by --sort-by
option in kubectl:
kubectl get pods --all-namespaces -o wide --sort-by=.spec.nodeName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With