kubernetes更新逻辑与策略
帮助
kubectl explain deploy.spec.strategy revisionHistoryLimit #保存几个历史版本,默认10个 paused #暂停 kubectl explain deploy.spec.strategy.rollingUpdate #更新粒度设置 maxSurge #最多能超出几个pod maxUnavailable #最多有几个不可用pod
例1,如修改此例中的replicas数量后,执行apply 更新
vim deploy-demo.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: myapp-deploy namespace: default spec: replicas: 2 selector: matchLabels: app: myapp release: canary template: metadata: labels: app: myapp release: canary spec: containers: - name: myapp image: ikubernetes/myapp:v1 ports: - name: http containerPort: 80
声明式更新
kubectl apply -f deploy-demo.yaml
打补丁方式更新
kubectl patch deployment myapp-deploy -p '{"spec":{"replicas":5}}'
set image 方式更新
更新一个,然后暂停
kubectl set image deployment myapp-deploy myapp=ikubernetes/myapp:v3 && kubectl rollout pause deployment myapp-deploy kubectl set image daemonsets filebeat-ds filebeat=ikubernetes/filebeat:5.6.6-alpine #继续进行更新操作 kubectl rollout resume demloyment myapp-deploy
查看滚动更新历史
kubectl rollout --help kubectl rollout history --help kubectl rollout history deployment myapp-deploy
查看更新过程
kubectl rollout status deployment myapp-deploy
调整更新粒度(打补丁方式)
kubectl patch deployment myapp-deploy -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}}}}'
回滚
kubectl rollout --help kubectl rollout undo deployment myapp-deploy kubectl rollout undo deployment myapp-deploy --to-revison=3
停留在世界边缘,与之惜别