⚡ ~/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 84 of 207 in Kubernetes
Junior / Associate DevOps [L1] Kubernetes Advanced Scenarios Core Fundamentals [L1]
🎯 Target Role / Context: Kubernetes Scenario #73 (L1) · Advanced Scenarios

Q: How do you scale a deployment to 5 replicas?

kubectl scale deployment <name> --replicas=5 or update spec.replicas.

#Kubernetes #Advanced Scenarios #L1 #Container Orchestration #K8s
🎙️ Candidate Opening & Architectural Context
"To <strong>scale a deployment to 5 replicas</strong>, run <code>kubectl scale deployment my-app --replicas=5</code>, or better, set <code>spec.replicas: 5</code> in the manifest in Git and let your pipeline apply it. This looks like a trivial L1 question, but interviewers use it to hear whether you know the difference between imperative and declarative changes, what happens when an HPA or GitOps controller also manages the replica count, and how to verify that five pods are actually ready and not merely requested."
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>scale a deployment to 5 replicas</strong>, run <code>kubectl scale deployment my-app --replicas=5</code>, or better, set <code>spec.replicas: 5</code> in the manifest in Git and let your pipeline apply it. This looks like a trivial L1 question, but interviewers use it to hear whether you know the difference between imperative and declarative changes, what happens when an HPA or GitOps controller also manages the replica count, and how to verify that five pods are actually ready and not merely requested.

1️⃣

Mental Model: Scaling Changes Desired State Only

Scaling edits the replica count on the Deployment's scale subresource; the controllers do the rest.

  • No new revision: scaling does not create a new ReplicaSet and does not appear in kubectl rollout history. Only pod template changes do.
  • Controller loop: the Deployment controller updates the ReplicaSet's replicas; the ReplicaSet creates pods; the scheduler places them. Any of those steps can stall. After the ReplicaSet is updated, pod creation is asynchronous, so the command returning does not mean the pods exist yet.
  • Who owns the number: exactly one actor should own spec.replicas: a human or Git, or an HPA. Two owners will fight.
  • Scale subresource: kubectl scale talks to the /scale subresource, which is why it also works on ReplicaSets, StatefulSets and custom resources that expose it.
2️⃣

Hands-on: Scale a Deployment to 5 Replicas

Three ways to do it, with different audit trails.

# Imperative, with a guard against concurrent edits
kubectl scale deployment my-app -n prod --current-replicas=3 --replicas=5

# Patch equivalent
kubectl patch deployment my-app -n prod -p '{"spec":{"replicas":5}}'

# Declarative: edit spec.replicas: 5 in deployment.yaml, then
kubectl apply -f deployment.yaml

# Expected
# deployment.apps/my-app scaled
  • Imperative: kubectl scale is fastest in an incident. The --current-replicas flag adds a precondition so the command fails if someone else already changed the count. Add -n prod every time or set the namespace in your context, because scaling the same-named Deployment in the wrong namespace is a classic incident cause.
  • Patch: kubectl patch against the Deployment works in scripts and uses the same API field.
  • Declarative: change replicas in the manifest, commit, and apply. This is the production default because it is reviewed and reproducible.
Advertisement
3️⃣

Verify That Five Replicas Are Actually Ready

Scaled is not the same as ready, so check the whole chain.

kubectl get deploy my-app -n prod
# NAME     READY   UP-TO-DATE   AVAILABLE
# my-app   5/5     5            5
kubectl get pods -n prod -l app=my-app -o wide
  • Rollout status: kubectl rollout status deploy/my-app -n prod waits until all replicas are available.
  • Counts: kubectl get deploy my-app -n prod should read 5/5 in READY. If it reads 3/5, inspect the missing pods.
  • Pending pods: kubectl get pods -n prod -l app=my-app --field-selector=status.phase=Pending lists those waiting for capacity, and kubectl describe pod gives the scheduler reason.
  • Service backends: five ready endpoints should appear in kubectl get endpointslices -n prod -l kubernetes.io/service-name=my-app.
  • Why READY lags: new pods must pull the image, start, and pass their readiness probe, so READY rising from 3 to 5 over several seconds or minutes is normal. A stall is the signal to investigate.
4️⃣

Failure Modes: HPA, GitOps and Capacity

Most 'scaling did not stick' reports come from a second controller.

  • HPA present: if a HorizontalPodAutoscaler targets the Deployment, it will overwrite your manual value on its next evaluation. Change minReplicas/maxReplicas on the HPA instead, and omit spec.replicas from the manifest so applies do not reset it.
  • GitOps reverts: Argo CD or Flux with self-heal will set it back to the Git value within minutes. Commit the change rather than running the imperative command.
  • No room: pods stay Pending due to insufficient CPU or memory, ResourceQuota, or anti-affinity. Scaling the number does not create capacity unless the Cluster Autoscaler or Karpenter adds nodes.
  • Downstream limits: five replicas multiply database connections and rate limits; check connection pool sizes before scaling out.
  • StatefulSets differ: scaling a StatefulSet adds pods one at a time in order by default, and scale-down removes the highest ordinal first, so it behaves differently from a Deployment.
5️⃣

Production Practice

Make scaling safe and observable.

  • PDB and spread: a PodDisruptionBudget and topology spread keep the new replicas from landing on one node.
  • Readiness probes: new pods receive traffic only after their probe passes, so scale-out under load is safe only with correct probes. For planned events, scale out ahead of the load rather than reacting, and scale back after verifying error rates and latency are stable.
  • Audit: imperative scaling should be rare and visible; API audit logs record the scale subresource update.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Before running kubectl scale, check kubectl get hpa for the same target; if an HPA or GitOps self-heal owns the replica count, your manual 5 will be reverted."
⚡ 60-Second Elevator Pitch Talking Points
  • kubectl scale deployment my-app --replicas=5 changes desired state on the scale subresource, with no new rollout revision.
  • I verify with rollout status, READY 5/5 and five ready EndpointSlice addresses, and read events for Pending pods.
  • In production I change replicas in Git, or the HPA bounds, because HPA and GitOps otherwise overwrite manual scaling.
⛔ 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. Scaling manually while an HPA targets the same Deployment The HPA recalculates the count and overwrites your value, so the change silently disappears.
  2. Declaring success when the command prints scaled That only means desired state changed; pods may be Pending for lack of capacity or failing readiness.
  3. Keeping spec.replicas in a manifest that an HPA manages Every kubectl apply resets the count to the manifest value and causes a scaling flap.
  4. Scaling out without checking downstream connection limits More replicas can exhaust database connections and turn a capacity fix into an outage.
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 →