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
circle-info

List only the pods with environment 'production'

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

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
circle-info

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

circle-info

in operator to get pods with specific release version range

circle-info

Example of notin operator

Deleting pods with labels

circle-info

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

Last updated

Was this helpful?