ReplicaSets and DaemonSets
Compare ReplicaSets and Replication Controllers
Replication Controllers (RC) have been replaced by ReplicaSets (RS) in the Kubernetes release .1.9
RS and RC are two resources that work similarly. But RS is more flexible in the Label Selector property. With RC it can only select Pods whose Label is exactly the same as its Label. RS allows using a number of expressions in the Label Selector section.
For example, RC cannot select both Pods at the same time, while RS can, by specifying a label selector with the value . In addition, RS also supports using Operators with the following properties:env=productionenv=testingenv=***matchExpressions
Copy
There are four basic Operators: In, NotIn, Exists, DoesNotExist. Allows one RS to select many different Pods.
Use ReplicaSets
We will use ReplicaSets (RS) to deploy Pods instead of using RC. The RS configuration will be the same as the RC, just with different properties . Create a file named :selectorhello-rs.yaml
Copy
Run the command :apply
Copy
Check if RS was created successfully:
Copy
Copy
Check if the number of Pods created by RS is equal to the field :replicas
Copy
Copy
If there are 2 pods created, we have run RS successfully. As we can see, the way RS works is similar to RC, the only difference is the attribute configuration . This may be a question that appears in an interview if we meet someone who likes to ask about theory.selector
To delete RS, we run the command :delete
Copy
DaemonSets
Unlike RS, RS-managed Pods can be deployed in any Node, and in one Node, many Pods can be run. DaemonSets are used when we want to deploy a Pod for each Node, the number of Pods will correspond to the number of selected Nodes, it will not have the .replicas
One of the applications of DaemonSets is in log collection and system monitoring. When we need to collect logs from Node, we only need one Pod for each Node, because if there are more than one Pod collecting logs from Node, there will be duplicate logs when storing.
Another example is that we need to monitor all Nodes using SSD drives. We will type the label into the Node as follows:
Copy
Then specify the DaemonSets properties:nodeSelector
Copy
When creating DaemonSets, it only deploys Pods to Nodes labeled as .disk=ssd
Learn more about DaemonSets here .
Conclude
We have finished learning about ReplicaSets and DaemonSet. RS is an advanced resource of RC and is used in practice. Use DaemonSet when you want to deploy a Pod for each Node.
Last updated