What is the Kubernetes ReplicaSet Object
The purpose of a ReplicaSet is to maintain a stable set of identical Pods. One can specify the number of Pods one desires, known as replicas, and the ReplicaSet will ensure that the desired number of pods are always kept available.
Here's a sample ReplicaSet definition file.
apiVersion: apps/v1 kind: ReplicaSet metadata: name: a-replica-set spec: # replicas is used to specify the number of Pods we want to have running replicas: 1 # selector is used to tell ReplicaSet which Pods we want it to maintain selector: matchLabels: key: value # template is used to tell ReplicaSet to create Pods with this template (definition) template: metadata: name: name-of-pod labels: key: value spec: containers: - name: container-name image: image-name
One thing to note that it is recommended to use Deployments over ReplicaSets when we want to use ReplicaSets. When we use Deployments, we don't have to worry about managing our ReplicaSets. Read this for more info.