题目要求

  1. 更新 namespace ckad00015 中的 Deployment webapp 的比例缩放配置 将 maxSurge 设置为 10% ,将 maxUnavailable 设置为 4
  2. 更新 Deployment webapp 以让容器镜像 lfccncf/nginx 使用版本标签 1.13.7
  3. 将 Deployment webapp 回滚至 前一版本

参考

https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/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
28
29
30
31
32
33
34
35
36
37
38
cat ~/ckad/15-deployment-rollout
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: ckad00015
spec: {}
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: webapp
name: webapp
namespace: ckad00015
spec:
replicas: 1
selector:
matchLabels:
app: webapp
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: webapp
spec:
containers:
- image: lfccncf/nginx:1.12.2
name: nginx
resources: {}
status: {}
1
2
3
4
5
6
7
8
9
10
11
12
# 1.修改deployment 滚动升级策略
kubectl -n ckad00015 edit deployments.apps webapp
rollingUpdate:
maxSurge: 10%
maxUnavailable: 4
# 2.修改image版本
kubectl -n ckad00015 set image deployment webapp nginx=lfccncf/nginx:1.13.7
# 3.回滚上一个版本
kubectl -n ckad00015 rollout undo deployment webapp

# 测试验证
kubectl -n ckad00015 get deployments.apps webapp -oyaml | grep image