Skip to content

Usage of daemonset

homepage-banner

What is a DaemonSet?

A DaemonSet is a Kubernetes resource that ensures that a copy of a pod is running on each node in a cluster. It is used to run a single instance of a pod on each node. The DaemonSet controller is responsible for creating and managing pods that are created by a DaemonSet.

Creating a DaemonSet

To create a DaemonSet, we need to create a YAML file that defines the DaemonSet resource. Here is an example YAML file:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: example-daemonset
spec:
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: example-image

This YAML file creates a DaemonSet that runs a single instance of a pod on each node. It uses the example-image as the container image.

kubectl create -f example-daemonset.yml

Updating a DaemonSet

To update a DaemonSet, we need to edit the YAML file and apply the changes. Here is an example YAML file:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: example-daemonset
spec:
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: new-example-image

This YAML file updates the example-daemonset DaemonSet to use the new-example-image as the container image.

Deleting a DaemonSet

To delete a DaemonSet, we need to use the kubectl delete command. Here is an example command:

kubectl delete daemonset example-daemonset

This command deletes the example-daemonset DaemonSet.

Conclusion

In conclusion, a DaemonSet is a Kubernetes resource that ensures that a copy of a pod is running on each node in a cluster. It is used to run a single instance of a pod on each node. In this blog post, we have discussed the cheat sheet of kubectl daemonset. We have covered creating, updating, and deleting a DaemonSet. We hope this cheat sheet will help you manage your Kubernetes clusters more efficiently.

Leave a message