Q: How do you check what labels are on a node?
kubectl get node <n> --show-labels or kubectl describe node <n>. Add labels: kubectl label node <n> key=value.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: To <strong>check what labels are on a node</strong>, run <code>kubectl get node <name> --show-labels</code> or <code>kubectl describe node <name></code>; to see a few specific labels as columns across all nodes, use <code>-L</code>. Interviewers ask this simple question to see if you can move from inspection to action: filtering nodes by label, understanding the well-known labels cloud providers set, and knowing how labels drive nodeSelector, affinity and topology spread.
Mental model: what node labels are for
Labels are key-value metadata on the Node object, used by schedulers, controllers and humans to group nodes.
- Sources: the kubelet sets built-in labels such as
kubernetes.io/hostname,kubernetes.io/osandkubernetes.io/arch; cloud providers add zone, region and instance type; admins add custom ones. - Well-known labels:
topology.kubernetes.io/zone,topology.kubernetes.io/regionandnode.kubernetes.io/instance-typeare used by spread constraints and affinity. - Role labels:
node-role.kubernetes.io/control-planeis a label whose key encodes the role; what you see as ROLES inkubectl get nodescomes from these. - Labels versus taints: labels attract or select; taints repel. They are often used together.
- Why interviewers care: every scheduling rule you write (nodeSelector, nodeAffinity, topology spread) is only as correct as the labels on the nodes, so reading labels is the first diagnostic step for Pending pods.
Hands-on: check what labels are on a node with kubectl
Use the output format that matches your goal, from a quick look to scripting.
kubectl get nodes --show-labels
kubectl get nodes -L topology.kubernetes.io/zone,node.kubernetes.io/instance-type
kubectl get node worker-1 -o jsonpath='{.metadata.labels}' | jq .
kubectl describe node worker-1 | sed -n '/^Labels:/,/^Annotations:/p'
- All labels of every node:
kubectl get nodes --show-labels. Output is dense, so prefer the next options for readability. - Specific labels as columns:
-L topology.kubernetes.io/zone,node.kubernetes.io/instance-typeadds one column per key. - One node in detail:
kubectl describe node worker-1prints a Labels: block, one per line. - Machine readable:
-o jsonpath='{.metadata.labels}'or-o json | jq .metadata.labels. - Reading output quickly: the LABELS column is comma separated, so for a single key it is faster to request it with
-Lthan to scan the full string. - Control-plane nodes:
kubectl get nodes -l node-role.kubernetes.io/control-planelists them, because the role is encoded in the label key rather than its value. - Count by label: pipe a column to sort and uniq to see how many nodes sit in each zone, which quickly shows imbalance.
Filter, add and remove labels
Selectors let you find the nodes behind a scheduling decision.
kubectl get nodes -l disktype=ssd
kubectl label node worker-1 disktype=ssd
kubectl label node worker-1 disktype=nvme --overwrite
kubectl label node worker-1 disktype-
- Equality selector:
kubectl get nodes -l disktype=ssd; set-based:-l 'topology.kubernetes.io/zone in (us-east-1a,us-east-1b)'. - Add a label:
kubectl label node worker-1 disktype=ssd; change an existing one with--overwrite. - Remove a label:
kubectl label node worker-1 disktype-(trailing dash). - Use it: a pod with
nodeSelector: {disktype: ssd}now schedules only on matching nodes. - Safety: labelling a node changes which pods can match, but does not move running pods; only new scheduling decisions are affected.
- Multiple labels at once:
kubectl label node worker-1 tier=db team=datasets several in one call, andkubectl label nodes --all env=staginglabels every node.
Edge cases and debugging scheduling with labels
A pod stuck Pending often comes down to a label mismatch.
- Pending pod:
kubectl describe podsays didn't match Pod's node affinity/selector; compare the pod's selector with the node labels. - Typos and case: label keys and values are case-sensitive.
- Manual labels are lost: nodes recreated by an autoscaler or node group do not keep hand-applied labels. Define them in the node group or kubelet config (
--node-labels). - Restricted prefix: with the NodeRestriction admission plugin, kubelets cannot set labels under
node-restriction.kubernetes.io/, which makes that prefix suitable for isolation labels. - Compare both sides: run
kubectl get pod <pod> -o jsonpath='{.spec.nodeSelector}'next to the node labels to see the mismatch at a glance.
Production practice: label conventions
Consistent labels turn scheduling into policy.
- Define at provisioning: set labels through Terraform, node groups or Karpenter NodePools instead of ad hoc kubectl.
- Namespaced keys: use your own domain prefix, for example
example.com/workload-tier. - Combine with taints: label and taint dedicated nodes so only intended pods run there.
- Audit: a periodic
kubectl get nodes -Lreport catches drift. - Cloud specifics: managed services also add provider labels, such as node pool or capacity type, which are useful selectors for spot versus on-demand placement; check what your provider sets rather than assuming.
- Document the contract: publish the list of supported node labels and their meaning so application teams write selectors against a stable, reviewed set instead of guessing.
- I check node labels with kubectl get nodes --show-labels, -L for chosen keys, or describe node for one node.
- I filter with -l selectors and confirm that a pod's nodeSelector or affinity matches what the node actually carries.
- I automate labels in node groups or provisioners rather than labelling nodes by hand.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Labelling nodes manually with kubectl in an autoscaled cluster Replaced nodes come up without the label and pods become unschedulable.
- Parsing --show-labels output with grep for scripting The format is meant for humans; use jsonpath or jq on metadata.labels.
- Using labels alone to dedicate nodes Without a matching taint, other pods can still land on those nodes.
- Overwriting well-known labels such as topology.kubernetes.io/zone Spread constraints and volume topology rely on them being accurate.