Kubernetes
Deployment & Rollout
Manage a replicated, rolling-updated workload.
By EZ4Code Team
deploymentrolloutreplica
Code
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels: { app: api }
template:
metadata:
labels: { app: api }
spec:
containers:
- name: api
image: myapp:2.0
ports: [{ containerPort: 8080 }]
# Rollout commands
# kubectl rollout status deployment/api
# kubectl rollout undo deployment/api
# kubectl rollout history deployment/apiExplanation
A Deployment manages a ReplicaSet and provides declarative rolling updates and rollbacks. The selector must match the template's labels so the controller can find its Pods. maxSurge and maxUnavailable tune how aggressive the rollout is, balancing speed against availability.
More Kubernetes Snippets
Pod Manifest
Define a standalone Pod with a container, env, and probe.
Service Types
Expose Pods via ClusterIP, NodePort, and LoadBalancer services.
ConfigMap & Secret
Inject configuration and sensitive data into containers.
Ingress Routing
Route external HTTP traffic to services by host and path.
Labels & Selectors
Tag resources and query them with selectors.
kubectl Basics
Common kubectl commands for everyday operations.