Skip to main content

Recreate

Ce este recreate?

Recreate este strategia "all-or-nothing": toate pod-urile vechi sunt terminate înainte ca pod-urile noi să înceapă.

Diferența față de rolling update:

  • rolling update: gradual, zero downtime
  • recreate: instant, cu downtime

Cum funcționează?

Setare: strategy.type = Recreate

Procesul:

  1. Deploymentul vede că e nevoie de actualizare
  2. Toate pod-urile vechi sunt terminate
  3. După ce toate sunt terminate, toate pod-urile noi sunt create
  4. Aplicația are downtime în timpul procesului
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: recreate-app
labels:
app: recreate-app
version: "1"
spec:
replicas: 3
strategy:
type: Recreate # All pods terminated before new ones created
selector:
matchLabels:
app: recreate-app
template:
metadata:
labels:
app: recreate-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: recreate-app-v1 # This ConfigMap contains our custom index.html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: recreate-app-v1
data:
index.html: |
<!DOCTYPE html>
<html>
<head><title>Recreate - V1</title></head>
<body>
<h1>Recreate Deployment</h1>
<h2>Version 1.0</h2>
<p>Old version before recreate</p>
</body>
</html>
---
apiVersion: v1
kind: Service
metadata:
name: recreate-app-service
spec:
type: LoadBalancer
selector:
app: recreate-app
ports:
- port: 80
targetPort: 80
  • app-v2.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: recreate-app
labels:
app: recreate-app
version: "2"
spec:
replicas: 3
strategy:
type: Recreate # All pods terminated before new ones created
selector:
matchLabels:
app: recreate-app
template:
metadata:
labels:
app: recreate-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: recreate-app-v2 # This ConfigMap contains our custom index.html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: recreate-app-v2
data:
index.html: |
<!DOCTYPE html>
<html>
<head><title>Recreate - V2</title></head>
<body>
<h1>Recreate Deployment</h1>
<h2>Version 2.0</h2>
<p>NEW version after recreate!</p>
<p>Notice the downtime was unavoidable</p>
</body>
</html>
  • executați comenzile de mai jos pe fișierele de mai sus:
# STEP 1: Deploy versiunea 1

kubectl apply -f app-v1.yaml

STEP 2: Verificam pod-urile

kubectl get pods -l app=recreate-app

# STEP 3: Verifiă serviciul

curl localhost

# Ar trebui să vedem "Version 1.0"

# STEP 4: în alt terminal, pornim monitoring
kubectl get pods -l app=recreate-app -w

# STEP 5: Deploy versiunea 2 cu Recreate

kubectl apply -f app-v2.yaml

# Observăm în terminalul de monitoring că există un moment de timp în care nu avem niciun pod.

# CLEANUP

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