Sobes.tech
Junior — Middle

What is the difference between deployment and replica set in Kubernetes?

sobes.tech AI

Answer from AI

In Kubernetes, a ReplicaSet is responsible for maintaining a specified number of pod replicas, ensuring their availability and replacing failed instances.

A Deployment is a higher-level abstraction that manages ReplicaSets. It provides a convenient way to update applications (e.g., rolling updates), roll back to previous versions, and manage deployment strategies.

Simply put:

  • ReplicaSet monitors the number of pods and their health.
  • Deployment manages the ReplicaSet, providing easier updates and lifecycle management.

Example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image:v1

This Deployment will create a ReplicaSet, which in turn creates 3 pods with the specified container.