<p>When creating a <code>Deployment</code> and <code>HorizontalPodAutoscaler</code> together in a Helm chart, should the deployment’s <code>.spec.replicas</code> be set to <code>null</code>, or should it be unset, or should it be set to some value between the hpa’s <code>minReplicas</code> and <code>maxReplicas</code>?</p>
<p>When you create a hpa, the hpa controller manages the deployment’s <code>.spec.replicas</code>, so when you update the deployment’s other fields you shouldn’t change the replicas.</p>
<p>Comparing to <code>kubectl apply</code> declarative config, you can modify other fields of the deployment without modifying <code>.spec.replicas</code> if you leave <code>.spec.replicas</code> 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 <code>kubectl apply edit-last-applied</code> to avoid accidentally scaling down to 1 when removing the field (<a href="https://github.com/kubernetes/kubernetes/issues/67135" rel="nofollow noreferrer">kubernetes/kubernetes#67135</a>). So with <code>kubectl apply</code> it is possible to apply a deployment while not touching <code>.spec.replicas</code>.</p>
<p>What is the correct way to <code>helm upgrade</code> a deployment’s other fields without changing its scaling?</p>

<p>I checked <a href="https://github.com/helm/helm/issues/7090" rel="nofollow noreferrer">here</a> and If I understand correctly there are 2 ways of doing that.</p>
<p>1.Add if statement as a workaround.</p>
<p>There is comment about it added by @naseemkullah.</p>
<blockquote>
<p>so the workaround is to add an if statement around the deployment's spec.replicas to not template it if HPA is enabled</p>
</blockquote>
<hr />
<p>2.Remove replicas field completely, then it should respect the replicas number managed by HPA.</p>
<p>There is <a href="https://github.com/helm/helm/issues/7090#issuecomment-605870466" rel="nofollow noreferrer">comment</a> about it added by @tianchengli.</p>
<blockquote>
<p>If I remove replicas field completely, it will respect the replicas number managed by HPA.</p>
</blockquote>
