1、deployment中设置拉取镜像策略、拉取镜像权限的秘钥
在deployment中设置以下参数
spec:
# 拉取镜像权限的秘钥
imagePullSecrets:
- name: registry-pull-secret
containers:
- name: nginx
image: nginx:latest
# 镜像拉取策略
imagePullPolicy: IfNotPresent
# @@@@@@@@@@@@@@@@@@@@@
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 20%
maxUnavailable: 1
minReadySeconds: 5
revisionHistoryLimit: 10 # 设置可记录的版本数
2、保证拉取镜像权限的秘钥在当前deployment的命名空间中
3、滚动更新
cd rollout
# 使用nginx的1.14.1版本
kubectl apply -f nginx-deployment.yaml
# 对deployment进行扩容
kubectl -n rollout scale deployment nginx-deployment --replicas=10
# 通过修改镜像进行版本更新
kubectl -n rollout set image deployment/nginx-deployment nginx=test.com/project/nginx:1.15.4
kubectl -n rollout rollout status deployments/nginx-deployment
# 命名空间是-n rollout
kubectl -n rollout rollout undo deployments/nginx-deployment
查看history
kubectl -n rollout rollout history deployments/nginx-deployment
kubectl rollout undo deployment nginx-deployment --to-revision=5
# 历史版本记录
kubectl apply -f nginx-deployment.yaml --record
参考:https://www.cnblogs.com/justmine/p/8688828.html
http://www.ipcpu.com/2017/09/kubernetes-rolling-update/