This guide teaches how to define, deploy, self-heal, and scale a Kubernetes ReplicaSet for high availability and fault tolerance.
In this guide, you’ll learn how to define, deploy, self-heal, and scale a Kubernetes ReplicaSet. A ReplicaSet ensures a specified number of Pod replicas are running at all times, providing high availability and fault tolerance.
The selector.matchLabels field must exactly match the labels under template.metadata.labels. The labels in metadata.labels on the ReplicaSet itself are not used for Pod selection.
For reference, here’s the original Pod definition in pods/nginx.yaml:
From the project root, apply the ReplicaSet manifest:
Copy
Ask AI
cd replicasetskubectl create -f replicaset.yaml
Verify the ReplicaSet and its Pods:
Copy
Ask AI
kubectl get replicaset# NAME DESIRED CURRENT READY AGEkubectl get pods# NAME READY STATUS RESTARTS AGE# myapp-replicaset-8nxxl 1/1 Running 0 24s# myapp-replicaset-jlgr2 1/1 Running 0 24s# myapp-replicaset-pm4rl 1/1 Running 0 24s