K8s resource: Deployment
30 May 2025 (Updated 1 June 2025)
On this page
What is a Deployment?
A Deployment in Kubernetes is a workload resource used to manage the deployment, scaling, and updating of stateless application pods.
A Deployment is used to ensure that a specific number of pod replicas are running and available at all times. If a pod crashes or is deleted, the Deployment resource will create a new one to replace it.
It also performs rolling updates (rolls out new updates one pod at a time) to ensure your application is always available even during new deployments.
Example Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: web
image: nginx:1.25
ports:
- containerPort: 80
This config will tell K8s to:
- Always ensure 3 pods of the
nginx:1.25
container are running. - Update the pods one by one when you change the image.
YAML lines:
apiVersion
kind
: The kind of K8s componentmetadata
name
: The name of the deploymentlabels
:app
: ?
spec
replicas
: How many replicas of the Pods.selector
matchLabels
app
: ?
template
metadata
labels
app
Tagged:
Kubernetes