Skip to main content

Rolling update (rollout)

Ce este un rolling update?

Rolling ppdate este strategia implicită de deployment ân Kubernetes.

Caracteristici:

  • Actualizează pod-urile gradual
  • Asigură zero downtime
  • Permite rollback automat
  • Garantează disponibilitate continuă

Cum funcționează?

Principiul este următorul: înlocuiește câte un pod pe rând, menține serviciul disponibil.

Parametri importanți:

  • maxSurge - numărul maxim de pod-uri care pot fi create peste numărul dorit

    • maxSurge: 1 → Permite 1 pod extra (mai sigur, mai lent)
    • maxSurge: 25% → Permite 25% extra pod-uri
  • maxUnavailable - numărul maxim de pod-uri unavailable în timpul rollout-ului

    • maxUnavailable: 0 → Zero downtime garantat
    • maxUnavailable: 1 → Permite 1 pod down (mai rapid, mai riscant)
Task

Mai jos aveți două fișiere și executați comenzile de mai jos:

  • app-v1.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: rolling-app
labels:
app: rolling-app
version: "1"
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Can have 1 extra pod during rollout
maxUnavailable: 0 # No unavailable pods (zero downtime)
selector:
matchLabels:
app: rolling-app
template:
metadata:
labels:
app: rolling-app
version: "1"
spec:
containers:
- name: web-server
image: nginx:1.21
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
configMap:
name: rolling-app-v1 # This ConfigMap contains our custom index.html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: rolling-app-v1
data:
index.html: |
<!DOCTYPE html>
<html>
<head><title>Rolling Update - V1</title></head>
<body>
<h1>Rolling Update Deployment</h1>
<h2>Version 1.0</h2>
<p>This is the Rolling Update strategy demonstration.</p>
<p>Zero downtime deployment in action!</p>
</body>
</html>
---
apiVersion: v1
kind: Service
metadata:
name: rolling-app-service
spec:
type: LoadBalancer
selector:
app: rolling-app
ports:
- port: 80
targetPort: 80
  • app-v2.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: rolling-app
labels:
app: rolling-app
version: "2"
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Can have 1 extra pod during rollout
maxUnavailable: 0 # No unavailable pods (zero downtime)
selector:
matchLabels:
app: rolling-app
template:
metadata:
labels:
app: rolling-app
version: "2"
spec:
containers:
- name: web-server
image: nginx:1.23
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
configMap:
name: rolling-app-v2 # This ConfigMap contains our custom index.html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: rolling-app-v2
data:
index.html: |
<!DOCTYPE html>
<html>
<head><title>Rolling Update - V2</title></head>
<body>
<h1>Rolling Update Deployment</h1>
<h2>Version 2.0</h2>
<p>This is the Rolling Update strategy demonstration.</p>
<p>Zero downtime deployment in action!</p>
<p style="color:green;">UPDATE COMPLETED SUCCESSFULLY!</p>
</body>
</html>
---
apiVersion: v1
kind: Service
metadata:
name: rolling-app-service
spec:
type: LoadBalancer
selector:
app: rolling-app
ports:
- port: 80
targetPort: 80
  • executați comenzile de mai jos pe fișierele de mai sus:
# STEP 1: Deploy versiunea 1

kubectl apply -f app-v1.yaml

# Verificăm pod-urile în alt terminal:
kubectl get pods -l app=rolling-app -w

# STEP 2: Acceseaza aplicatia

# Verifică serviciul:
kubectl get service rolling-app-service

# Accesează aplicatia:
curl localhost

# Sau în browser:
# open htp://localhost

# Ar trebui să vezi "Version 1.0"

# STEP 3: Deploy versiunea 2 (Rolling Update)

kubectl apply -f app-v2.yaml

# Observați ce se întamplă cu podurile:
kubectl get pods


STEP 4: Testeaza Zero Downtime

# în alt terminal, pornești un loop de testare cu timestamp:
for i in {1..30}; do echo -n "$(date +%H:%M:%S) - "; curl -s localhost | grep Version; sleep 1; done

# în terminal-ul curent, după câteva secunde, deploy versiunea 2:
kubectl apply -f app-v2.yaml

# Observăm în terminal-ul de testare - trecerea de la V1 la V2 fără erori.

# STEP 5: Verifică rollout-ul

kubectl rollout status deployment rolling-app
kubectl rollout history deployment rolling-app

# STEP 6: Rollback (opțional)

kubectl rollout undo deployment rolling-app

# CLEANUP

kubectl delete deployment rolling-app
kubectl delete service rolling-app-service
kubectl delete configmap rolling-app-v1 rolling-app-v2