How to create a Deployment manifest?
· Category: Kubernetes
Short answer
A Deployment manifest is a YAML file that defines the desired state of a stateless application. It specifies the number of replicas, the Pod template, and update strategies.
Steps
- Set
apiVersion: apps/v1andkind: Deployment. - Define metadata including
nameandnamespace. - Set
spec.replicas. - Define
spec.selector.matchLabels. - Write the
spec.templatefor the Pods.
Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myapi:v1.0
ports:
- containerPort: 8080
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
Tips
- Always set resource requests and limits.
- Use
revisionHistoryLimitto cap stored revisions. - Label your Pods consistently with the selector.
Common issues
- Mismatched labels between selector and template cause the Deployment to create no Pods.
- Missing
apiVersionorkindresults in validation errors. - Container image pull failures leave Pods in
ImagePullBackOff.