DaemonSets
A DaemonSet ensures that all nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them automatically. When the nodes are deleted, they are not rescheduled but deleted.
So DaemonSet allows you to deploy a Pod across all nodes.
Preparation
If you are running this tutorial in Minikube, you need to add more nodes to run this part of the tutorial. Check the number of nodes you have delpoyed by running:
kubectl get nodes
If only one node is present then you need to create a new node by following the next steps:
NAME STATUS ROLES AGE VERSION
kube Ready master 54m v1.17.3
Having minikube
installed and in your PATH
, then run:
minikube node add -p devnation
Or if you do not have enough resources to add a new node with same resources as master node, you can create a new cluster with minial requirements.
minikube start --nodes 2 -p multinode --kubernetes-version='v1.26.1' --vm-driver='virtualbox' --memory=2048
kubectl get nodes
NAME STATUS ROLES AGE VERSION
kube Ready master 54m v1.17.3
kube-m02 Ready <none> 2m50s v1.17.3
Multi-node clusters are currently experimental and might exhibit unintended behavior. |
DaemonSet
DaemonSet is created using the Kubernetes DaemonSet
resource:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: quarkus-daemonset
labels:
app: quarkus-daemonset
spec:
selector:
matchLabels:
app: quarkus-daemonset
template:
metadata:
labels:
app: quarkus-daemonset
spec:
containers:
- name: quarkus-daemonset
image: quay.io/rhdevelopers/quarkus-demo:v1
kubectl apply -f apps/kubefiles/quarkus-daemonset.yaml
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
quarkus-daemonset-jl2t5 1/1 Running 0 23s 10.244.0.2 multinode <none> <none>
quarkus-daemonset-r64ql 1/1 Running 0 23s 10.244.1.2 multinode-m02 <none> <none>
Notice that an instance of the Quarkus Pod is deployed to every node.