DaemonSet is used to deploy resident background programs in the cluster, such as the log daemon. DaemonSet ensures that specified Pods are running on all or certain nodes. When you add new nodes to a cluster, Pods are deployed automatically. When nodes are removed from the cluster, Pods are repossessed automatically.
If a Pod has nodeSelector or affinity configured, the Pods managed by DaemonSet are scheduled according to existing policies. If not, the Pods are deployed on all nodes.
latest
or left empty, use Always
. Otherwise, use IfNotPresent
.Rolling updates of DaemonSet are only supported in Kubernetes v1.6 or later.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
Template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: k8s.gcr.io/fluentd-elasticsearch:1.20
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
The above sample YAML file comes from
https://kubernetes.io/docs/concepts/workloads/controllers/daemonset
. The container image may not be available during creation. The sample is only used to illustrate DaemonSet creation.
For more information, refer to Kubernetes official documentation.
kubectl create -f DaemonSet YAML filename
For example, to create a StatefulSet YAML file named fluentd-elasticsearch.yaml, run the following command:kubectl create -f fluentd-elasticsearch.yaml
kubectl get DaemonSet
A message similar to the one below indicates that the YAML file has successfully been created.NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
frontend 0 0 0 0 0 app=frontend-node 16d
Run the following command to view the update policy type of the DaemonSet.
kubectl get ds/<daemonset-name> -o go-template='{{.spec.updateStrategy.type}}{{"\n"}}'
DaemonSet has the following update policy types:
Run the following command to update a DaemonSet.
kubectl edit DaemonSet/[name]
Use this for debugging or verification. We do not recommended using it in production environments. You can update any DaemonSet parameter this way.
Run the following command to update the image of a specific container.
kubectl set image ds/[daemonset-name][container-name]=[container-new-image]
We recommend that you keep other DaemonSet parameters unchanged and only update the container image when updating your service.
kubectl rollout history daemonset /[name]
kubectl rollout history daemonset /[name] --revision=[REVISION]
kubectl rollout undo daemonset /[name]
To specify the rollback version, run the following command.kubectl rollout undo daemonset /[name] --to-revision=[REVISION]
Run the following command to delete a DaemonSet.
kubectl delete DaemonSet [NAME]
Was this page helpful?