Replication Controller and ReplicaSet serve the same purpose, but ReplicaSet is the next generation of Replication Controller.
A ReplicaSet ensures a specified number of pod replicas are running at all times. It maintains the desired state of the application by creating or deleting pods as needed.
User → Service → ReplicaSet → Pod 1 → Pod 2
Key features:
Self-healing
If a pod fails, a new one is automatically created to replace it.
When you edit a ReplicaSet, you will need to delete the previously deployed pods first, as it won’t auto-update existing pods.
The key difference between Replication Controller and ReplicaSet is that ReplicaSet requires a selector definition. The selector identifies the pods that the ReplicaSet will manage using label selectors.ReplicaSet can also manage pods that were not created as part of the ReplicaSet creation.
replicaset.yaml
apiVersion: apps/v1kind: ReplicaSetmetadata: name: replicaset-namespec: replicas: 3 selector: matchLabels: # must match the pod labels in the template section app: web-server template: metadata: name: pod-name labels: app: web-server spec: containers: - name: container-name image: web-server-image