Deployments and ReplicaSets
Use Deployments to manage replicas and rolling updates.
A Deployment is the controller you will use most often. It creates and manages ReplicaSets to keep replica counts and version updates under control.
Key points
- ReplicaSet owns replica counts
- Deployment owns version updates
- Rollbacks are managed by the Deployment
Example Deployment
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: nginx:1.25
Rollout and rollback
kubectl rollout status deploy/api
kubectl rollout history deploy/api
kubectl rollout undo deploy/api
Practical notes
- Start with a quick inventory:
kubectl get nodes,kubectl get pods -A, andkubectl get events -A. - Compare desired vs. observed state;
kubectl describeusually explains drift or failed controllers. - Keep names, labels, and selectors consistent so Services and controllers can find Pods.
Quick checklist
- The resource matches the intent you described in YAML.
- Namespaces, RBAC, and images are correct for the target environment.
- Health checks and logs are in place before promotion.