Learn about ReplicaSet in Kubernetes

When a Pod in the Kubernetes system encounters a problem, it cannot fix itself, which will make our application unstable if there is any problem with Pod. To solve this problem, we need to use ReplicaSet to ensure that the number of Pods required for our application is always stable. That means, if a Pod has a problem, ReplicaSet will re-create that Pod for us. How is it in details? Let’s look at this tutorial together!

For example, I need to make sure that Kubernetes always has 2 Pods to run my huongdanjava application, I will define the spec file of ReplicaSet as follows:

In the spec definition above, the “kind: ReplicaSet” is the Kubernetes object name we need to create with the name and the Labels assigned to this ReplicaSet object are defined in the metadata section. The main part of the ReplicaSet object definition is in the spec section, which defines how many Pods we need, how to use Pod with Label, and the information that the Pods will be used in the template section. After defined ReplicaSet object, you can use the command “kubectl apply” to submit this ReplicaSet for Kubernetes as follows:

Result:

Learn about ReplicaSet in Kubernetes

Check if ReplicaSet is in Kubernetes:

you will see the following result:

Learn about ReplicaSet in Kubernetes

Check the information of ReplicaSet:

Learn about ReplicaSet in Kubernetes

Check the number of Pods available:

You will see the following result:

Learn about ReplicaSet in Kubernetes

Here, due to my Kubernetes, already had a Pod named huongdanjava which I created in the tutorial about Label and Selector in Kubernetes with Label match with the definition of ReplicaSet in this tutorial so you can see 2 Pods maintained for ensuring the definition of ReplicaSet.

If now I delete Pod huongdanjava:

then check Pod, you will see the following result:

Learn about ReplicaSet in Kubernetes

As you can see, a new Pod has been created while Pod huongdanjava is being deleted.

Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment