kubernetes deployment
kubernetes pod update strategies
ReplicaSet FTW
- update template
- delete legacy kubernetes pods
- wait
Drawback
Service interruption while the kubernetes ReplicaSet creates the kubernetes pods with the new template.
ReplicaSet + kubernetes service
- create a new kubernetes ReplicaSet dedicated to the new version
- when all kubernetes pods are
READ
, change the selector in the kubernetes service - delete the old kubernetes ReplicaSet
Drawback
Needs to have both versions at a time, hence twice the resource consumption.
Manual rolling update
Drawback
Lots of manual operations, hence error prone.
Deployment
Enter Deployment
:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: foobar
spec:
replicas: 3
selector:
matchLabels:
app: foobar
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: foobar
spec:
containers:
- name: app
image: foobar/k8s-training-deploy: v1
# checking if deployment went well
$ kubectl apply -f foobar-deployment-v1.yml
$ kubectl rollout status deployment foobar
Waiting for deployment "foobar" rollout to finish: 0 of 3 updated replicas are available...
deployment foobar successfully rolled out
$ kubectl get deploy -l app=foobar
$ kubectl get rs -l app=foobar
$ kubectl get po -l app=foobar
# update version
$ kubectl apply -f foobar-deployment-v2.yml --record
deployment.apps/foobar configured
$ kubectl get rs -l app=foobar
# get history
kubectl rollout history deploy frontend
# rollback
kubectl rollout undo deployment frontend ‐‐to‐revision= 20
Controlling the “Rollout”
maxSurge
(default 25%): how many kubernetes pod instances greater than targeted replicas is allowed- e.g. for
nb_replicas=4
, there won’t be more than5
kubernetes pods inREADY
- e.g. for
maxUnavailable
(default 25%): how many kubernetes pod instances can be unavailable than targeted replicas is allowed- e.g. for
nb_replicas=4
, there won’t be less than3
kubernetes pods inREADY
- e.g. for
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 30%
maxUnavailable: 0
Example 1: replicas=3, maxSurge=1, maxUnavailable=1
Example 2: replicas=3, maxSurge=1, maxUnavailable=0
Re-creation strategy
If you can’t have both versions at the same time, there is another strategy: Recreate
- delete existing kubernetes pods
- create new kubernetes pods
spec:
strategy:
type: Recreate
There is a service interruption!