K8s Deployment Strategies:
- To Move or update one version to another version
- Recreat:
- Kill all old pods at once and create new pods
- Will have down time
flowchart LR
A[v1 v1 v1] --> B[all stopped - downtime] --> C[v2 v2 v2]
spec:
Strategy:
type: recreate
- Rolling Update:
- it is default upgrade Strategie in k8s deployment
- pods will be replace gradually , a few min of time
- No downtime
flowchart LR
S1[v1 v1 v1 v1] --> S2[v1 v1 v1 v2] --> S3[v1 v1 v2 v2] --> S4[v1 v2 v2 v2] --> S5[v2 v2 v2 v2]
spec:
replicas: 4
Strategy:
type: RollingUpdate
RollingUpdate:
maxSurge: 1
maxUnavailable: 0
- Bule/green Deployment:
- Run Two full versions , switch traffic by changing the service selector
flowchart LR
U[Users] --> SVC[Service<br/>selector: version=blue]
SVC --> B[Blue v1 - live]
G[Green v2 - idle/testing]
SVC -. switch selector .-> G
- Canary deployement:
- creating pods and load will be distubuted by %
- Traffic will divided by Ratio
- No downtime
flowchart LR
U[Users] --> SVC[Service<br/>selector: app=myapp]
SVC -->|~90%| S[Stable v1 x 9 Pods]
SVC -->|~10%| C[Canary v2 x 1 Pod]
- A/B Testing:
- it is similar as Canary deployment , based on request it will create group and random percentage to scale the new version
flowchart LR
U[Request] --> R{Router<br/>header / cookie?}
R -->|group A| A[v1]
R -->|group B| B[v2]
- Shadow:
- copy the traffic to new version
- safer to test work loads
- it is required service mesh or proxy configuration.
flowchart LR
U[Users] --> P[Proxy / Mesh]
P --> V1[v1 - responds to users]
P -. mirrored copy .-> V2[v2 - response ignored]
Choosing the Right Strategy
| Situation | Strategy |
|---|---|
| Dev/test, downtime acceptable | Recreate |
| Normal production release | Rolling Update |
| Need instant rollback, can afford 2x resources | Blue/Green |
| Risky change, want gradual exposure | Canary |
| Compare features by user group | A/B Testing |
| Validate under real traffic with zero risk | Shadow |
Task:
- create deployment using api referance Deployment API Offical docs
- create new deployment Strategies like recreat , rolling update bule-green methods
- try from apps , like jenkins , nop, apache2 , nginx
docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk21
