8. Query Resource Using Label
8.1. Overview
This section contains queries to get Pod
resource using label.
8.2. Queries
8.2.1 Query pods of backend category
kubectl get pod -l category=backend -n NAMESPACE_NAME
1
Output:
8.2.2 Query pods of frontend category
kubectl get pod -l category=frontend -n NAMESPACE_NAME
1
Output:
8.2.3 Query pods of datasource category
kubectl get pod -l category=datasource -n NAMESPACE_NAME
1
Output:
8.3. Advance Filtering
8.3.1. Query pods of backend and datasource category
kubectl get pod -l 'category in (backend, datasource)' -n NAMESPACE_NAME
1
Output:
8.3.2. Query pods that are not in backend and datasource category
kubectl get pod -l 'category notin (backend, datasource)' -n NAMESPACE_NAME
1
Output:
8.3.2. Query pods of frontend category with all labels
kubectl get pod -l 'category in (frontend)' -n NAMESPACE_NAME --show-labels
1
Output:
NOTE
In the above command "--show-labels" arg will display all the labels assigned to the resource.