美文网首页
备战CKA每日一题——第9天

备战CKA每日一题——第9天

作者: 小E的私房菜 | 来源:发表于2020-03-11 14:03 被阅读0次

第九题: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
执行结果: image.png
  • 步骤3:清理(删除)在此任务期间生成的任何新的k8s API对象:
sudo kubectl delete -f kual00201.yaml

相关文章

网友评论

      本文标题:备战CKA每日一题——第9天

      本文链接:https://www.haomeiwen.com/subject/ofvqjhtx.html