apiVersion: v1
kind: ReplicationController
metadata:
name: kubia-v1
labels:
app: kubia
spec:
replicas: 3
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v1
name: nodejes
---
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
kubectl create namespace update-rollback
kubectl apply -f kubia-v1.yaml -n update-rollback
curl http://暴露地址
kubectl rolling-update kubia-v1 kubia-v2 --image=luksa/kubia:v2 -n update-rollback
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
labels:
app: kubia
spec:
replicas: 3
selector:
matchLabels:
app: kubia
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v1
name: nodejes
---
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
kubectl create namespace update-rollback
kubectl apply -f kubia.yaml -n update-rollback
curl http://暴露地址
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
labels:
app: kubia
spec:
replicas: 3
minReadySeconds: 10
selector:
matchLabels:
app: kubia
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v2
name: nodejes
---
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
minReadySeconds:表示新创建pod至少要成功运行多久之后才能视为可用
通过strategy属性可以设置升级的方式。默认为滚动升级(RollingUpdate),另一种为删除所有旧Pod再创建新pod(Recreate)
maxSurge:允许超出期望副本数的百分比的pod数量。也可以直接指定个数,默认值为1
maxUnavailable:允许不可用pod占期望副本数的百分比。也可以直接指定个数,默认值为1
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
labels:
app: kubia
spec:
replicas: 3
minReadySeconds: 10
selector:
matchLabels:
app: kubia
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v3
name: nodejes
---
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
kubectl rollout history deployment kubia -n update-rollback
kubectl rollout history deployment kubia --revision=2 -n update-rollback
kubectl rollout undo deployment kubia -n update-rollback
kubectl rollout undo deployment kubia --to-revision=1 -n update-rollback
通过revisionHistoryLimit可以限制历史版本的数量,默认为10
spec:
revisionHistoryLimit: 10
kubectl rollout pause deployment kubia -n update-rollback
kubectl rollout resume deployment kubia -n update-rollback
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
labels:
app: kubia
spec:
replicas: 3
minReadySeconds: 10
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: kubia
template:
metadata:
name: kubia
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v3
name: nodejes
readinessProbe:
periodSeconds: 1
httpGet:
path: /
port: 8080
---
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
查看升级状态可以发现升级流程一直没有继续下去
kubectl rollout status deployment kubia -n update-rollback
查看pod情况可以看到pod一直没到就绪状态,应该就绪探针检测到异常
kubectl get pods -n update-rollback
kubectl rollout undo deployment kubia -n update-rollback
helm list -n aim-upgrade-test2
helm history devops-wuvreb-register -n aim-upgrade-test2
回滚到指定版本
helm rollback devops-wuvreb-register 2 -n aim-upgrade-test2
helm status devops-wuvreb-register --show-desc -n aim-upgrade-test2