Getting Started with Kubernetes — Chapter # 03

Getting Started with Kubernetes — Chapter # 03

REPLICASET:

In K8s, whenever we are talking about the multiple copies of any resource like pods, we are actually referring to replicaset. ReplicaSet is the resource that helps creating and managing multiple copies of application in K8s. The replicaset notices the missing pod and creates a replacement pod.

ReplicaSet has three essential parts:
Label selector => determines what pods are in the ReplicaSet scope.
Replica count => specifies the desired number of pods that should be running.
Pod template\=> ReplicaSet uses to create pod.

How to create a replicaset?

Some Useful Commands:

To create the replica set:
kubectl create -f <file-name>.yaml

To check replicaset
kubectl get <file-name>

To delete resource
kubectl delete pod <pod-name>

If you delete the pod and then run again the command of (kubectl get pods), it will again create the new pods to fulfill the desired output. If you want to delete the pod then delete the replica set.

kubectl delete <file-name> <pod-name>

If to delete replica set but not pods then first list all
kubectl delete <file-name> <pod-name> --cascade=false

If to change the replicaset in runtime
kubectl edit <file-name> <pod-name>

Scale replica’s
kubectl scale <file-name> <pod-name> --replicas=5

This will scale the pods to 5.

CRON JOB:

This is another resource. Cronjob repeats the job after every set time which was not possible in job.

To be continued…