介绍
记录k8s的更新操作
更新的三种方式:
- kubectl edit 修改配置
- kubectl set image 修改镜像版本(只介绍该方法)
- kubectl patch 修改配置
更新回滚
以一个简单的deployment为例来进行说明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 2 revisionHistoryLimit: 10 selector: matchLabels: app: nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.12 ports: - containerPort: 80
|
创建deployment
1 2
| # --record:记录版本,没有该参数无法回滚 kubectl apply -f nginx-deployment.yaml --record
|
更新与回滚
只有spec.template.spec.containers.image或者spec.template.metadata.labels发生变化时才会出发更新rolout操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| kubectl set image deployment nginx-deployment nginx=nginx:1.14 --record
kubectl rollout history deployment nginx-deployment
kubectl rollout undo deployment nginx-deployment
kubectl rollout undo deployment nginx-deployment --to-revision=2
kubectl rollout status deploy nginx
kubectl rollout pause deployment nginx
kubectl rollout resume deployment nginx
|