title: Kubernetes: what's the difference between Deployment and Replica set?
body: <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>