OpsInit: ReplicaSet VS DaemonSet in Kubernetes

Kubernetes API is growing day by day and they are adding new features every day. The latest feature they added was DaemonSet.

Although they had ReplicaSet,  DaemonSet is the K8 object they added. Let’s see the difference.

ReplicasSet will ensure that the number of pods (defined in our config file) is always running in our cluster. Does not matter in which worker node they are running. The scheduler will schedule the pods on any node depending upon the free resources. If one of our nodes goes down then all pods running on the node will be randomly scheduled on different nodes as per the resource availability. In this way, ReplicaSet ensures that the number of pods of an application is running on the correct scale as specified in the conf file.

replicasSet.png

Whereas in the case of DaemonSet it will ensure that one copy of pod defined in our configuration will always be available on every worker node.

The total # of pods running in DaemonSet = Number of worker nodes in our cluster

If a new node is added in our cluster then DaemonSet will automatically allocate pod on that node. Similarly, if a node is deleted then the pod running on the node is also destroyed, it will not reschedule the pod on different nodes as in case of ReplicaSet.

daemonSet

Let’s take a scenario where we have to create a pod containing nginx image in it. Below are the configuration files for creating a ReplicaSet and DaemonSet. Save this configuration in DemonSet.yml file.

This is the configuration of a DaemonSet for nginx.

To create the Deamon Set, execute below commands.

 kubectl create -f DemonSet.yml

This daemonSet will create a pod in every node running in our cluster.

The configuration of ReplicaSet:-

This ReplicaSet will make sure that 3 replicas are present in our cluster everytime whether our node is up or down. The scheduler will take care on which node to schedule pod depending upon the free resources on the node.

Hope this blog was helpful in seeing the difference between DaemonSet and ReplicaSet. Also, you can refer the link below Click Here

Knoldus-Scala-spark-services-company

Written by 

Sachin is a software consultant having more than 0.5 years of experience. He loves to learn trending technologies. Sachin is familiar with languages such as Java, Scala and is currently working on DevOps technologies /tools like Kubernetes, Jenkins, Ansible, Docker, Bamboo.

Leave a Reply

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!

%d bloggers like this: