Kubernetes Rolling Upgrade (Rollout&Rollback)
Thanks for these blogs
https://tachingchen.com/tw/blog/Kubernetes-Rolling-Update-with-Deployment/ https://www.linux.com/learn/rolling-updates-and-rollbacks-using-kubernetes-deployments
Yaml file
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginxstor
spec:
#serviceName: "nginxstor"
replicas: 2
template:
metadata:
labels:
app: nginxstor
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nginxstor
topologyKey: kubernetes.io/hostname
containers:
- name: nginxstor
image: 192.168.51.130:5000/uwebserverv6
ports:
- containerPort: 8000
minReadySeconds: 5
strategy:
# indicate which strategy we want for rolling update
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1Adding rolling strategy strategy for rolling upgrade.
minReadySeconds: 5
strategy:
# indicate which strategy we want for rolling update
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
Sleep minReadySecond after container's daemon running and it then start another container.
Rollout (upgrade)
kubectl set image deployment nginxstor nginxstor=192.168.51.130:5000/uwebserverv7 --recordIt will start rolling upgrade now
There are several ways to upgrade container, but I prefer this way since with less dependency.
--record is notify kubernetes to record the history, and you will see it later.
To check the status
kubectl rollout status deployment nginxstorRollback (downgrade)
To check the version
kubectl rollout history deployment nginxstor
deployments "nginxstor"
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image deployment nginxstor nginxstor=192.168.51.130:5000/uwebserverv7 --record=trueLet's go back to revision 1
kubectl rollout undo deployment nginxstor --to-revision=1Try it, it works amazingly.
No comments:
Post a Comment