Kubernetes Handbook
  • Introduction
  • Prerequisites
    • What is Containerization
    • What is Docker
    • Difference between Docker and VM
  • Features of Kubernetes
    • What is Kubernetes
    • Features of Kubernetes - 1
    • Features of Kubernetes - 2
    • Which Tool to Use for Orchestration
  • Architecture
    • Master Node
    • etcd and kubectl
    • Worker Nodes
  • Pods and Nodes
    • Nodes
    • Pods
  • Controllers
    • Benefits of Controllers
    • Kinds of Controllers
  • Minikube
    • What is Minikube
  • Installation and Running (Mac OS)
    • Installation
    • Running Hello World Application
  • Labels Namespaces and Selectors
    • Labels
    • Namespaces
    • Selectors
  • Health Checks Rollouts and Rollbacks
    • Health Checks
    • Rollouts and Rollbacks
  • Config Maps and Secrets
    • Config Maps
    • Secrets
  • Running Jobs
    • How to Run Jobs
  • Dashboard and Debugging
    • Kubernetes Dashboard
    • Debugging
Powered by GitBook
On this page
  • Working with Multiple Selectors
  • In and Not In Operator
  • Deleting pods with labels

Was this helpful?

  1. Labels Namespaces and Selectors

Selectors

PreviousNamespacesNextHealth Checks

Last updated 3 years ago

Was this helpful?

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'.

241B
helloworld-pod-with-labels.yml