Selectors

Selectors help to choose and find the resources that you are particularly looking for using labels.

For working with selectors, here is an example find you can proceed with. The same can be extended to deployments and services.

$ kubectl create -f <file name for deployment>
$ kubectl get pods - -show-labels
$ kubectl get pods - -selector env=production

List only the pods with environment 'production'

$ kubectl get pods --selector dev-lead=carisa

List only the pods with development lead 'Carisa'

Working with Multiple Selectors

$ kubectl get pods --selector env=production,dev-lead=carisa
$ kubectl get pods --selector env=production,dev-lead!=carisa

Search for multiple labels with negation. This command returns the list of pods with environment as 'production' and dev-lead not equal to 'Carisa'.

In and Not In Operator

$ kubectl get pods -l 'release-version in (1.0,2.0)' 

in operator to get pods with specific release version range

$ kubectl get pods -l 'release-version notin (1.0,2.0)'

Example of notin operator

Deleting pods with labels

$ kubectl delete pods -l dev-lead=carisa

Deletes all pods with a particular dev-lead 'Carisa'.

Last updated