<p>Both replica set and deployment have the attribute <code>replica: 3</code>, what's the difference between deployment and replica set? Does deployment work via replica set under the hood?</p>
<p>configuration of deployment</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  labels:
    my-label: my-value
spec:
  replicas: 3
  selector:
    matchLabels:
      my-label: my-value
  template:
    metadata:
      labels:
        my-label: my-value
    spec:
      containers:
        - name: app-container
          image: my-image:latest
</code></pre>
<p>configuration of replica set</p>
<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
  labels:
    my-label: my-value
spec:
  replicas: 3
  selector:
    matchLabels:
      my-label: my-value
  template:
    metadata:
      labels:
        my-label: my-value
    spec:
      containers:
        - name: app-container
          image: my-image:latest
</code></pre>
<blockquote>
<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#when-to-use-a-replicaset" rel="noreferrer">Kubernetes Documentation</a></p>
<p>When to use a ReplicaSet</p>
<p>A ReplicaSet ensures that a specified number of pod replicas are running at any given time. However, Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features. Therefore, we recommend using Deployments instead of directly using ReplicaSets, unless you require custom update orchestration or don't require updates at all.</p>
<p>This actually means that you may never need to manipulate ReplicaSet objects: use a Deployment instead, and define your application in the spec section.</p>
</blockquote>

<p>Deployment resource makes it easier for updating your pods to a newer version.</p>
<p>Lets say you use <em>ReplicaSet-A</em> for controlling your pods, then You wish to update your pods to a newer version, now you should create <em>Replicaset-B</em>, scale down <em>ReplicaSet-A</em> and scale up <em>ReplicaSet-B</em> by one step repeatedly (This process is known as <strong>rolling update</strong>). Although this does the job, but it's not a good practice and it's better to let K8S do the job.</p>
<p>A <strong>Deployment resource</strong> does this automatically without any human interaction and increases the abstraction by one level.</p>
<p><strong>Note</strong>: Deployment doesn't interact with pods directly, it just does rolling update using ReplicaSets.</p>
