模拟题目:
设置配置环境:
[candidate@node-1] $ kubectl config use-context k8s
Task
namespace goshawk 中名为 chipmunk-service 的 Service 指向名为 current-chipmunk-deployment 的 Deployment 创建的 5 个 Pod 你可以在 /ckad/goshawk 中找到 current-chipmunk-deployment 的清单文件。
- 在同一 namespace 中创建一个 相同的 Deployment 名为 canary-chipmunk-deployment
- 修改 Deployment 以便
- 在 namespace goshawk 中运行的 Pod 的最大数量为 10 个
- chipmunk.service 流量的 40% 流向 Pod canary-chipmunk-deployment
参考:
https://kubernetes.io/zh-cn/docs/concepts/cluster-administration/manage-deployment/#canary-deployments https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/deployment/#canary-deployment
kubectl -h
kubectl scale -h
解答:
切换环境
kubectl config use-context k8s
copy一份yaml文件,并进行编辑, 修改为canary-chipmunk-deployment部署的yaml
cd /ckad/goshawk/
cp current-chipmunk-deployment.yaml canary-chipmunk-deployment.yaml
vim canary-chipmunk-deployment.yaml
canary-chipmunk-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: canary-chipmunk-deployment #修改为题目要求
namespace: goshawk #修改为题目要求
spec:
replicas: 1
selector:
matchLabels:
app: canary-chipmunk-deployment #修改为题目要求
run: dep-svc #确保和current-chipmunk-deployment都有此标签
template:
metadata:
labels:
app: canary-chipmunk-deployment #修改为题目要求
run: dep-svc #确保和current-chipmunk-deployment都有此标签
spec:
containers:
- image: vicuu/nginx:hi
name: nginx
创建canary pod
kubectl apply -f canary-chipmunk-deployment.yaml
根据题目, 10个pod ,current 60%,canary 40%, 如果是其他比例也要灵活, 比如8:2等
kubectl -n goshawk scale deployment current-chipmunk-deployment --replicas 6
kubectl -n goshawk scale deployment canary-chipmunk-deployment --replicas 4
查看pod
kubectl -n goshawk get pod
测试
kubectl -n goshawk get svc -owide
for i in {1..1000} ; do curl -qs 10.109.141.220;done | sort |uniq -c
进行1000此请求计算百分比, 流量6:4