Create a replicaset
Course: Kubernetes Part 1 - chapter 14
Let’s not worry about deployments, lets just create a replicaset that starts 3 pods
- Create
rs.yml
apiVersion: apps/v1kind: ReplicaSetmetadata: name: nginx-replicasetspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80- Apply the manifest
kubectl apply -f rs.yml- Get the rs details
kubectl get rs
NAME DESIRED CURRENT READY AGEnginx-replicaset 3 3 3 23s- Check the pods
kubectl get pods
NAME READY STATUS RESTARTS AGEnginx-replicaset-7zp2v 1/1 Running 0 35snginx-replicaset-q264f 1/1 Running 0 35snginx-replicaset-vj42z 1/1 Running 0 35s- Try deleting a pod and check if it self heals
kubectl delete pod nginx-replicaset-7zp2vkubectl get pods- Try adding a pod with the
app=nginx
kubectl run nginx-pod --image=nginx --labels="app=nginx"- Ensure it gets terminated immedietely because the
rsalready has 3 pods - Delete the replicaset
kubectl delete rs nginx-deployment-576c6b7b6💡 Note the naming convention of the pods. The pods are named after the
replicasetfollowed by a unique id (for eg nginx-replicaset-vj42z)