Hands-on Lab·Certified Kubernetes Administrator
Labels, Selectors and nodeSelector
Labels are the only way anything in Kubernetes finds anything else. Read the labels your cluster gave itself, learn the four selector forms including set-based and negation, then use one to pin a Deployment to a specific node.
Scheduling and Placement Guide 39 of 103 Beginner
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 25 min
Node names and ages are this lab's. The built-in label set is standard.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node (labelled disk=ssd) | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when one object has to find another - a Service finding Pods, a Deployment tracking what it owns, a Pod landing on the right node. This matters because labels are the only addressing system Kubernetes has: nothing here finds anything by name.
- reading the labels the cluster has already put on its own nodes
- adding labels of your own, which count for exactly as much as the built-in ones
- selecting four different ways, since
-ltakes far more than equality - placing a workload with
nodeSelector, the simplest tool that uses them - removing a label with a trailing hyphen, the same convention taints use
Before you start
- A cluster with a few nodes and
kubectl. - Permission to label nodes, which is cluster-scoped.
- Nothing else. This is the mechanism everything else in Kubernetes is built on, so it is worth doing early.
-
Your cluster is already covered in labels
-
Add your own
-
Four ways to select
-
Use a label to place a workload
-
Remove the labels