Kubernetes Deployments
Deployments are a higher-level abstraction that manages ReplicaSets and provides declarative updates to Pods along with many other features.
Pods Don't Have These Capabilities
- Self-healing
- Scaling
- Updates
- Rollback
Deployments Can Do All This!
- Self-healing
- Scaling
- Updates
- Rollback
Deployments Overview
A Deployment manages a single pod template. You create a deployment for each microservice:
- Front-end
- Back-end
- Image-processor
- Creditcard-processor
Deployments and ReplicaSets
- Deployments create ReplicaSets in the background
- Don't interact with the ReplicaSets directly
Deployment
Rolling updates and rollbacks
ReplicaSet
Self-healing, scalability
Pod
Pod
Pod
Deployment Configuration
Key Configuration Parameters
Replicas
Number of pod instances to maintain
Revision History Limit
Number of previous iterations to keep
Strategy
- RollingUpdate: Cycle through updating pods
- Recreate: All existing pods are killed before new ones are created
Final Deployment Definition
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-example
spec:
replicas: 3
revisionHistoryLimit: 3
selector:
matchLabels:
app: nginx
env: prod
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
type: prod
spec:
containers:
- name: nginx
image: nginx:stable-alpine
ports:
- containerPort: 80
kubectl Deployments Cheat Sheet
Imperative Way
Create a Deployment
kubectl create deploy [deploymentName] --image=busybox --replicas=3 --port=80
Apply from YAML
kubectl apply -f [definition.yaml]
List Deployments
kubectl get deploy
Get Deployment Info
kubectl describe deploy [deploymentName]
List ReplicaSets
kubectl get rs
Delete a Deployment
kubectl delete -f [definition.yaml]
kubectl delete deploy [deploymentName]
kubectl delete deploy [deploymentName]