how to tell which pods are in a specific priority class?

9/12/2018

Very basic question here: once I have created a priority-class, how do I query which pods are associated with / are in that priority class?

kubectl describe priorityclass <name>

gives details about the priority class itself

And I can get the details of the individual pod via:

kubectl get pod <name> -o yaml

But how do I query all pods that are in a particular priority class?

-- Lana Nova
kubernetes
pod-priority

2 Answers

9/12/2018

This will do it:

kubectl get pods -o=jsonpath='{.items[?(@.spec.priorityClassName=="highpriority")].metadata.name}{"\n"}'

Change highpriority with whatever label you are using for your priority.

Hope it helps.

-- Rico
Source: StackOverflow

12/29/2019

This will do it:

kubectl get pods --all-namespaces -o custom-columns=NAME:.metadata.name,PRIORITY:.spec.priorityClassName

You can change the namespace for specific one by replacing --all-namespaces with --namespace=<your_namespace>.

-- HowToDoIT
Source: StackOverflow