Certified Kubernetes Administrator Study Guide – Scheduling – Use label selectors to schedule pods

  • Labels are key-value pairs
  • When using label selectors to specify node selection you add the following section to the yaml specification:
  accelerator: nvidia-tesla-p100

This example is telling Kubernetes to select only nodes with the label accelerator = nvidia-tesla-p100.

Where accelerator is the is the key and nvidia-tesla-p100 is the value.

  • The nodeSelector section comes within the spec: section after the definition of the containers.
  • Matching resources must satisfy all of the specified label constraints, although they can have additional labels as well e.g. the above example requires that a node has a label of accelerator with a value of nvidia-tesla-p100 in order to match the selector for the pod but it could also have a label of production with a value of true. The pod does not have to have this label specified in its selector statement.
  • Can also create a label on a node using kubectl:
kubectl label node vm-node1 environment=production
  • For services and replicationcontrollers targeting a set of pods label selectors are also used in this scenario they use the format:
  "component": "redis",


  component: redis

Can use kubectl with labels using:

kubectl get pods -l environment=production, tier=frontend

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close