Ensures a single pod per node
Kubernetes resource that ensures a single pod per node is the DaemonSet. A DaemonSet ensures that all (or some) nodes run a copy of a pod. When a new node is added to the cluster, the DaemonSet automatically schedules the defined pod on that node. If a node is removed from the cluster, the DaemonSet ensures that the corresponding pod is terminated.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: example-daemonset
spec:
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example-image:latest
- The selector specifies the labels to match nodes that should run the pod.
- The template defines the pod template with its associated containers.
A node with the label app=example-app is added to the cluster, a pod based on the specified template is automatically created on that node.
Keep in mind that DaemonSets are useful for scenarios where you want a specific pod to run on every node in the cluster, such as for monitoring agents, log collectors, or other system-level services.