DEV Community

Cover image for DevOps Interview: Replica sets vs Daemon sets
Aishwary Prakash
Aishwary Prakash

Posted on

DevOps Interview: Replica sets vs Daemon sets

Replica sets and Daemon sets are controllers in Kubernetes used to manage the lifecycle of Pods. They are used to manage Pods.

Let's check the differences between them.

  1. Replica sets ensure that a certain number of copies should be running on nodes. Daemon sets ensure exactly one copy running on all or certain nodes.

  2. Replica sets can be scaled up or down by assigning "replicas" field in the manifest file. Daemon sets scales automatically when the node number changes.

  3. Replica sets are used for stateless applications to maintain a certain number of instances of the application. Daemon sets are used for deploying backend services like monitoring agents, logging agents etc.

  4. Let's see the manifest file for both.

Replica sets-

 apiVersion: apps/v1
 kind: ReplicaSet
 metadata:
   name: <any name>
 spec:
   replicas: <any number>
   selector:
     matchLabels:
       app: <any name> # any label based on your need
   template:
     metadata:
       labels:
         app: <webserver>
     spec:
       containers:
       - name: <any name>
         image: nginx:latest
         ports:
         - containerPort: 80

Enter fullscreen mode Exit fullscreen mode

Daemon sets-

 apiVersion: apps/v1
 kind: DaemonSet
 metadata:
   name: <any name>
 spec:
   selector:
     matchLabels:
       app: < any name >  # any label based on your need
   template:
     metadata:
       labels:
         app: < any name>
     spec:
       containers:
       - name: <any name>
         image: fluentd:latest
         volumeMounts:
         - name: < your volume name>
           mountPath: /var/log   # any path directory on host 
       volumes:
       - name: < your volume name>
         hostPath:
           path: /var/log  # mounted volume on this path on host
node

Enter fullscreen mode Exit fullscreen mode

Example of Replica sets - any web application with certain replicas etc.
Example of Daemon sets - agent deployed to collect logs from nodes.

Still confused !!

No need to worry. Let’s take daily life example for both.

Replica sets-

In a restaurant, the waiters (replicas) form a ReplicaSet. The manager, acting as the controller, ensures enough waiters are available to serve customers efficiently. If a waiter is absent, the manager replaces them with another waiter to maintain the desired number of serving staff.

Daemon sets-

In a city with a fleet of garbage trucks, each truck (pod) is assigned a specific area (node) to collect trash. The fleet manager, acting as the DaemonSet, ensures a truck is always present in every area (node) for efficient waste management.

That’s all. Pat yourself on the back. :)

Hope you enjoyed it. Don’t forget to like it.

Top comments (0)