Kubernetes- DaemonSet
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.
Some typical uses of a DaemonSet are:
- running a cluster storage daemon on every node
- running a logs collection daemon on every node
- running a node monitoring daemon on every node
In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. A more complex setup might use multiple DaemonSets for a single type of daemon, but with different flags and/or different memory and cpu requests for different hardware types.
1. Deploy Pod on "all" worker nodes inside k8s cluster using DaemonSet
1a. YAML File:
--------------
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-ds
spec:
template:
metadata:
labels:
name: fluentd
spec:
containers:
- name: fluentd
image: gcr.io/google-containers/fluentd-elasticsearch:1.20
selector:
matchLabels:
name: fluentd
---------------------------------------------------------------------
1b. Create | Display | Validate
kubectl create -f fluentd-ds-allnodes.yaml
kubectl get po -o wide
kubectl get ds
kubectl describe ds fluentd-ds
*************************************************************************************************************************************************
2. Deploy Pod on "Subset" of worker nodes inside k8s cluster using DaemonSet
----------------------------------------
2a. Attach label to the nodes
kubectl get nodes
kubectl label nodes worker1 worker2 disktype=ssd
kubectl get nodes --show-labels
----------------------------------------
2b. YAML
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-ds
spec:
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx-container
image: nginx
nodeSelector:
disktype: ssd
selector:
matchLabels:
name: nginx
----------------------------------------
2c. Create | Display | Validate
kubectl create -f nginx-ds-subsetnodes.yaml
kubectl get po -o wide
kubectl get ds
kubectl describe ds nginx-ds
********************************************************************************
3. Cleanup
kubectl delete ds fluentd-ds
kubectl delete ds nginx-ds
kubectl get po
Comments
Post a Comment