What is the difference between Deployment, StatefulSet, and DaemonSet?
sobes.tech AI
Answer from AI
In Kubernetes, there are several types of controllers for managing pods, each solving different tasks:
-
Deployment — manages the creation and updating of a set of pod replicas. Used for stateless applications where scalability and seamless updates (rolling update) are important. It allows easy scaling of the number of pods.
-
StatefulSet — designed for stateful applications where a stable pod identity, startup and shutdown order, and state preservation are important (e.g., databases). StatefulSet provides unique pod names and stable persistent volumes for each.
-
DaemonSet — ensures that a copy of a pod is running on each (or selected) node in the cluster. Used for running system agents, logging, monitoring, network proxies, and other services that need to run on all nodes.
In brief:
- Deployment — for scalable stateless applications.
- StatefulSet — for stateful applications with state preservation and startup order.
- DaemonSet — for running pods on each cluster node.
Example usage:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx
Deployment will create 3 nginx replicas.
For a stateful database, it is better to use StatefulSet, and for monitoring agents — DaemonSet.