Exclude spec.replicas from Argo CD sync to prevent overwriting spec.replicas values managed by HPA.
Applications with one replica by default
Comment out the replicas field in the Deployment manifest. Argo CD only syncs fields present in Git, so omitting replicas lets HPA manage it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
# do not include replicas in the manifests if you want replicas to be controlled by HPA
# replicas: 1
template:
spec:
containers:
- image: nginx:1.7.9
name: nginx
ports:
- containerPort: 80
...
Applications with multiple replicas by default
For manifests with multiple replicas, commenting out the field breaks defaults. Instead, configure Argo CD to ignore spec.replicas via Diffing Customization to let HPA control replica counts.
Two scopes: application-level (one application) and system-level (all applications in a Fleet instance).
Application-level configuration
Configure .spec.ignoreDifferences in the Application resource. This applies only to that application.
By default, the rule applies to all Deployments in the application. To target a specific Deployment, uncomment and set the name and namespace fields.
Thegroupfield refers to the Kubernetes API group without the version (for example,apps, notapps/v1).
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-test
namespace: argocd
spec:
ignoreDifferences:
- group: apps
kind: Deployment
#name: test
#namespace: default
jsonPointers:
- /spec/replicas
...
System-level configuration
Configure the argocd-cm ConfigMap to ignore spec.replicas across all applications in the Fleet instance.
For ACK One GitOps, controlplane-kcm must be configured alongside kube-controller-manager in managedFieldsManagers.
apiVersion: v1
data:
...
resource.customizations.ignoreDifferences.all: |
managedFieldsManagers:
- kube-controller-manager
- controlplane-kcm
jsonPointers:
- /spec/replicas
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
Next steps
-
Enable HPA for your application.
-
HPA uses specific scaling algorithms to calculate target replica counts.