Skip to content

Removing replicaCount from deployment when HPA is configured

Gustavo Oliveira requested to merge gustoliv/gitlab-runner:main into main

What does this MR do?

This merge request removes replica count from deployment when HPA is configured

Migrating Deployments and StatefulSets to horizontal autoscaling
When an HPA is enabled, it is recommended that the value of spec.replicas of the Deployment and / or StatefulSet be removed from their [manifest(s)](https://kubernetes.io/docs/reference/glossary/?all=true#term-manifest). If this isn't done, any time a change to that object is applied, for example via kubectl apply -f deployment.yaml, this will instruct Kubernetes to scale the current number of Pods to the value of the spec.replicas key. This may not be desired and could be troublesome when an HPA is active.

Keep in mind that the removal of spec.replicas may incur a one-time degradation of Pod counts as the default value of this key is 1 (reference [Deployment Replicas](https://kubernetes.io/docs/concepts/workloads/controllers/deployment#replicas)). Upon the update, all Pods except 1 will begin their termination procedures. Any deployment application afterwards will behave as normal and respect a rolling update configuration as desired. You can avoid this degradation by choosing one of the following two methods based on how you are modifying your deployments:

Why was this MR needed?

This MR enable the HPA to work properly. At this time, when HPA is configured to autoscale Gitlab Runners, the new runners keep in terminating status infinitely. This occurs because deployment is hard-coded to require only 1 replica.

What's the best way to test this MR?

Create a new file named values_hpa_enabled.yaml with the following content:

hpa:
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metricName: gitlab_runner_jobs
      targetAverageValue: 400m

Execute helm template -s templates/deployment.yaml -f values_hpa_enabled.yaml .

The generated template must not have the replica property.

Just to check, execute the 2 commands below:

Should return replica count:

helm template -s templates/deployment.yaml . | grep replicas

Should NOT return replica count:

helm template -s templates/deployment.yaml -f values_hpa_enabled.yaml . | grep replicas
Edited by Gustavo Oliveira

Merge request reports