Q: How do you scale a deployment to 5 replicas?
kubectl scale deployment <name> --replicas=5 or update spec.replicas.
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.
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 scaletalks to the/scalesubresource, which is why it also works on ReplicaSets, StatefulSets and custom resources that expose it.
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 scaleis fastest in an incident. The--current-replicasflag adds a precondition so the command fails if someone else already changed the count. Add-n prodevery 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 patchagainst the Deployment works in scripts and uses the same API field. - Declarative: change
replicasin the manifest, commit, and apply. This is the production default because it is reviewed and reproducible.
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 prodwaits until all replicas are available. - Counts:
kubectl get deploy my-app -n prodshould read5/5in READY. If it reads3/5, inspect the missing pods. - Pending pods:
kubectl get pods -n prod -l app=my-app --field-selector=status.phase=Pendinglists those waiting for capacity, andkubectl describe podgives 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.
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/maxReplicason the HPA instead, and omitspec.replicasfrom 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.
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.
- 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.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Scaling manually while an HPA targets the same Deployment The HPA recalculates the count and overwrites your value, so the change silently disappears.
- Declaring success when the command prints scaled That only means desired state changed; pods may be Pending for lack of capacity or failing readiness.
- 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.
- Scaling out without checking downstream connection limits More replicas can exhaust database connections and turn a capacity fix into an outage.