2

When creating a Deployment and HorizontalPodAutoscaler together in a Helm chart, should the deployment’s .spec.replicas be set to null, or should it be unset, or should it be set to some value between the hpa’s minReplicas and maxReplicas?

When you create a hpa, the hpa controller manages the deployment’s .spec.replicas, so when you update the deployment’s other fields you shouldn’t change the replicas.

Comparing to kubectl apply declarative config, you can modify other fields of the deployment without modifying .spec.replicas if you leave .spec.replicas unset the first time the deployment is created, so that the 3-way diff ignores that field when the deployment is applied in the future. Or to omit the field after creation time, you have to use kubectl apply edit-last-applied to avoid accidentally scaling down to 1 when removing the field (kubernetes/kubernetes#67135). So with kubectl apply it is possible to apply a deployment while not touching .spec.replicas.

What is the correct way to helm upgrade a deployment’s other fields without changing its scaling?

yonran
  • 18,156
  • 8
  • 72
  • 97
  • Hi @yonran, I checked [here](https://github.com/helm/helm/issues/7090) and If I understand correctly there are 2 ways of doing that. First would be to add if statement as mentioned [here](https://github.com/helm/helm/issues/7090#issuecomment-605682145). Second would be to simply remove replicas field completely, then it should respect the replicas number managed by HPA, there is [comment](https://github.com/helm/helm/issues/7090#issuecomment-605759355) about it. Could you check above comments and let me know if that answer your question? – Jakub Nov 10 '20 at 14:30

1 Answers1

1

I checked here and If I understand correctly there are 2 ways of doing that.

1.Add if statement as a workaround.

There is comment about it added by @naseemkullah.

so the workaround is to add an if statement around the deployment's spec.replicas to not template it if HPA is enabled


2.Remove replicas field completely, then it should respect the replicas number managed by HPA.

There is comment about it added by @tianchengli.

If I remove replicas field completely, it will respect the replicas number managed by HPA.

Jakub
  • 8,189
  • 1
  • 17
  • 31