<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment" rel="noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment</a> mentions that a <code>deployment</code> creates a <code>replicaSet</code> but appends a <code>pod-template-hash</code> to the name of the <code>replicaSet</code> and also adds <code>pod-template-hash</code> as <code>replicaSet</code>'s label.</p>
<p>my best guess is that <code>deployment</code> creates multiple <code>replicaSets</code> and this hash ensures that the replicas do not overlap. Is that correct?</p>

<p>Correct, the documentation states this really well:</p>
<blockquote>
<p>The <code>pod-template-hash</code> label is added by the Deployment controller to
every ReplicaSet that a Deployment creates or adopts.</p>
<p>This label ensures that child ReplicaSets of a Deployment do not
overlap. It is generated by hashing the <code>PodTemplate</code> of the ReplicaSet
and using the resulting hash as the label value that is added to the
ReplicaSet selector, Pod template labels, and in any existing Pods
that the ReplicaSet might have.</p>
</blockquote>
<p>This is necessary for a bunch of different reasons:</p>
<ul>
<li>When you apply a new version of a Deployment, depending on how the deployment is configured and on probes, the previous Pod / Pods could stay up until the new one / ones is not Running and Ready and only then is gracefully terminated. So it may happens that Pods of different <code>ReplicaSet</code> (previous and current) run at the same time.</li>
<li>Deployment History is available to be consulted and you may also want to rollback to an older revision, should the current one stops behaving correctly (for example you changed the image that needs to be used and it jsut crash in error). Each revision has its own ReplicaSet ready to be scaled up or down as necessary as explained in the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#checking-rollout-history-of-a-deployment" rel="noreferrer">docs</a></li>
</ul>
