Can not override replicas of deployment k8s
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When you cannot override the replicas field of a Kubernetes Deployment, it is almost always because a Horizontal Pod Autoscaler (HPA) is managing the replica count, or because your manifest is being overwritten by a GitOps tool (ArgoCD, Flux). The HPA continuously adjusts replicas based on metrics, overriding any manual kubectl scale or manifest change within seconds. To fix this, either modify the HPA's minReplicas/maxReplicas or remove the HPA entirely before manually scaling.
The Problem
The replica count reverts because something else is controlling it.
Cause 1: Horizontal Pod Autoscaler (HPA)
The HPA overrides the replicas field based on CPU/memory utilization. When you manually scale to 5, the HPA evaluates its metrics and scales back to what it calculates is needed.
Fix: Adjust the HPA
Fix: Remove the HPA Temporarily
Cause 2: GitOps Tool Overriding
If you use ArgoCD, Flux, or a similar GitOps tool, the tool continuously reconciles the cluster state with the Git repository. Manually changing replicas in the cluster is overwritten on the next sync.
Fix: Change Replicas in Git
Fix: Ignore Replicas in ArgoCD
This tells ArgoCD not to revert manual replica changes, allowing HPA or manual scaling to work alongside GitOps.
Cause 3: Kustomize or Helm Overriding
If you deploy with Kustomize or Helm, changing the Deployment manifest directly is overwritten on the next kustomize build or helm upgrade. Change the value in the Kustomize overlay or Helm values file.
Cause 4: Resource Quotas or Limits
Verifying What Controls Replicas
The managedFields output shows which controller last modified the replicas field.
Common Pitfalls
- Forgetting about HPA: The most common reason manual scaling does not stick. Always check
kubectl get hpabefore debugging replica issues. The HPA controller runs every 15 seconds by default and will quickly override manual changes. - Editing the Deployment but not the HPA: Setting
replicas: 5in the Deployment manifest while the HPA hasminReplicas: 2, maxReplicas: 4means the HPA immediately scales back to at most 4. The HPA's range takes precedence. - GitOps sync overwriting changes: ArgoCD and Flux continuously reconcile. Any kubectl change to a GitOps-managed resource is temporary. Always change the source (Git), not the live cluster.
- Node resources insufficient: Scaling up replicas works only if the cluster has enough CPU/memory. If nodes are full, new pods stay
Pending. Checkkubectl describe pod <pending-pod>for scheduling failures. - KEDA or custom controllers: Advanced autoscalers like KEDA (Kubernetes Event-Driven Autoscaling) also manage replicas. Check for ScaledObject resources:
kubectl get scaledobjects.
Summary
- HPA is the most common reason manual replica changes revert — it continuously adjusts replicas based on metrics
- Check for HPA:
kubectl get hpaand verifyminReplicas/maxReplicas - GitOps tools (ArgoCD, Flux) overwrite manual changes — update replicas in the Git source instead
- Use
ignoreDifferencesin ArgoCD to allow manual or HPA-managed scaling - Check resource quotas and node capacity if new replicas stay in
Pendingstate - Inspect
managedFieldsto determine which controller is managing the replicas field

