sajad torkamani

What is ReplicaSet?

ReplicaSet in Kubernetes is a workload resource that ensures a specified number of identical pods are running at all times.

The ReplicaSet ensures that if a pod crashes or is deleted that another is automatically created to replace it.

In practice, you rarely create a ReplicaSet. You instead use Deployments to manage ReplicaSets behind the scenes.

Example ReplicaSet YAML

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: web
          image: nginx
          ports:
            - containerPort: 80

This will:

  • Run 3 pods of nginx.
  • Automatically replace any crashed or terminated pods to ensure 3 pods are always running.
Tagged: Kubernetes