⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 134 of 207 in Kubernetes
Senior DevOps / SRE [L2] Kubernetes Additional Kubernetes Scenarios (Q101-Q200) Production Scenario [L2]
🎯 Target Role / Context: Kubernetes Scenario #124 (L2) · Additional Kubernetes Scenarios (Q101-Q200)

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.

#Kubernetes #L2 #Container Orchestration #K8s
🎙️ Candidate Opening & Architectural Context
"To <strong>check what labels are on a node</strong>, run <code>kubectl get node &lt;name&gt; --show-labels</code> or <code>kubectl describe node &lt;name&gt;</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."
Advertisement
⚡ Recommended Practice Lab

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 &lt;name&gt; --show-labels</code> or <code>kubectl describe node &lt;name&gt;</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.

1️⃣

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/os and kubernetes.io/arch; cloud providers add zone, region and instance type; admins add custom ones.
  • Well-known labels: topology.kubernetes.io/zone, topology.kubernetes.io/region and node.kubernetes.io/instance-type are used by spread constraints and affinity.
  • Role labels: node-role.kubernetes.io/control-plane is a label whose key encodes the role; what you see as ROLES in kubectl get nodes comes 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.
2️⃣

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-type adds one column per key.
  • One node in detail: kubectl describe node worker-1 prints 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 -L than to scan the full string.
  • Control-plane nodes: kubectl get nodes -l node-role.kubernetes.io/control-plane lists 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.
Advertisement
3️⃣

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=data sets several in one call, and kubectl label nodes --all env=staging labels every node.
4️⃣

Edge cases and debugging scheduling with labels

A pod stuck Pending often comes down to a label mismatch.

  • Pending pod: kubectl describe pod says 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.
5️⃣

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 -L report 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.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: use kubectl get nodes -L key1,key2 for a clean table, and define node labels in your node group or kubelet config so they survive node replacement."
⚡ 60-Second Elevator Pitch Talking Points
  • 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.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Labelling nodes manually with kubectl in an autoscaled cluster Replaced nodes come up without the label and pods become unschedulable.
  2. Parsing --show-labels output with grep for scripting The format is meant for humans; use jsonpath or jq on metadata.labels.
  3. Using labels alone to dedicate nodes Without a matching taint, other pods can still land on those nodes.
  4. Overwriting well-known labels such as topology.kubernetes.io/zone Spread constraints and volume topology rely on them being accurate.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →