All Products
Search
Document Center

Container Service for Kubernetes:Configure HPA for GitOps applications

Last Updated:Mar 15, 2024

Argo CD periodically synchronizes the status of applications in your Git repository with the applications in your cluster. This may conflict with pod scaling activities performed by the Horizontal Pod Autoscaling (HPA) feature. Therefore, you must avoid configuration conflicts when you use the HPA feature to control the number of replicated pods of a GitOps application. To do this, you need to configure the application. The configuration method varies based on the default number of replicated pods used by the application: one replicated pod and multiple replicated pods.

The application uses one replicated pod by default

If the default number of replicated pods for your application is one and you use HPA to control the number of replicated pods, you need to annotate the replicas parameter of the corresponding Deployment in the Git repository.

Example:

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
...

The application uses multiple replicated pods by default

If your application uses multiple replicated pods by default, you need to configure the pods based on Diffing Customization and ignore the differences in spec.replicas. This way, Argo CD ignores the replica setting and the number of replicated pods is controlled only by HPA.

The following two configuration methods are available: application-level configuration and system-level configuration. For more information, see Argo CD Diffing Customization.

Ignore application-level configuration differences

Application-level configurations take effect only on the resources of the specified application. Configure .spec.ignoreDifferences in the application to ignore changes in the spec.replicas parameter of the Deployment.

To specify a Deployment in this scenario, you need to specify the name and namespace of the Deployment.

Example:

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
  ...

Ignore system-level configuration differences

System-level configurations take effect on the resources of an entire Fleet instance. Configure argocd/argocd-cm to ignore changes in the spec.replicas parameter of Kubernetes resources managed by managers.

The manager controlplane-kcm must be configured for ACK One GitOps. Example:

apiVersion: v1
data:
  ...
  resource.customizations.ignoreDifferences.all: |
    managedFieldsManagers:
    - kube-controller-manager
    - controlplane-kcm
    jsonPointers:
    - /spec/replicas
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd

References