A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created.
The following is an example DaemonSet that runs a Prometheus container. Prometheus is an open source toolkit to monitor and alert. It is widely used for Kubernetes monitoring.
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: prometheus-daemonset
spec:
selector:
matchLabels:
tier: monitoring
name: prometheus-exporter
template:
metadata:
labels:
tier: monitoring
name: prometheus-exporter
spec:
containers:
- name: prometheus
image: prom/node-exporter
ports:
- containerPort: 80
$ kubectl create -f daemonset.yaml --record
N.B : The –record flag will track changes made through each revision.
$ kubectl get daemonsets/prometheus-daemonset
$ kubectl describe daemonset/prometheus-daemonset
$ kubectl get pods -lname=prometheus-exporter
First verify that the Prometheus pod was successfully deployed to the cluster nodes:
$ kubectl get pods -o wide
$ kubectl label node NODE_NAME app=prometheus-node
$ kubectl edit ds/prometheus-daemonset
Change the spec.template.spec to include a nodeSelector that matches the changed label:
nodeSelector:
app: prometheus-node
$ kubectl get ds/prometheus-daemonset
Run the following command to delete the DaemonSet:
$ kubectl delete -f daemonset.yaml