备战CKA每日一题——第9天
2020-03-11 本文已影响0人
小E的私房菜
第九题:Deployment创建:
题目:Create a deployment spce file that will:
- Launch 7 replicas of the redis image with the label:app_env_stage=dev
- Deployment name: kua100201
- Save a copy of this spec file to /opt/KUAL00201/deploy_spec.yaml
- When you are done,clean up (delete) any new k8s API objects that you produced during this task
解题思路:
本题考的是Deployment的创建方式,属于基础题型:
解题步骤:
- 步骤1: 使用kubectl run创建一个基础pod:
sudo kubectl run kual00201 --image=redis --generator=run-pod/v1 --dry-run -o yaml > kual00201.yaml
原始文件:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: kual00201
name: kual00201
spec:
containers:
- image: redis
name: kual00201
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
- 步骤2:修改yaml文件:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: kual00201
name: kual00201
namespace: ns-ehj
spec:
replicas: 7
selector:
matchLabels:
name: kual00201
template:
metadata:
labels:
name: kual00201
spec:
containers:
- image: redis
name: kual00201
执行结果:

- 步骤3:清理(删除)在此任务期间生成的任何新的k8s API对象:
sudo kubectl delete -f kual00201.yaml