• ckad认证考题核心概念


    核心概念(13%)

    题1:创建命名空间与pod

    题目:Create a namespace called 'mynamespace' and a pod with image nginx called nginx on this namespace

    题解:

    # 创建命令空间
    kubectl create namespace mynamespace
    # 使用命令创建nginx pod
    kubectl run nginx --image=nginx -n mynamespace
    

    题2:利用yaml创建pod

    题目:Create the pod that was just described using YAML

    题解:

    # 使用yaml文件创建pod,两者都可以
    kubectl create -f nginx_pod.yaml
    # nginx_pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      namespace: mynamespace
    spec:
      containers:
      - name: nginx
        image: nginx
        
    # 除了手敲yaml,官网复制,还可以命令生成
    kubectl run nginx --image=nginx --dry-run=client -n mynamespace -o yaml > pod.yaml
    

    题3:使用命令创建执行某一条命令的pod

    题目:Create a busybox pod (using kubectl command) that runs the command "env". Run it and see the output

    题解:

    kubectl run busybox --image=busybox --command -- env
    kubectl logs busybox
    

    题4:使用yaml创建执行某一条命令的pod

    题目:Create a busybox pod (using YAML) that runs the command "env". Run it and see the output

    题解:

    kubectl run busybox --image=busybox --command --dry-run=client -o yaml -- env > pod.yaml
    # pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: busybox
      name: busybox
    spec:
      containers:
      - command:
        - env
        image: busybox
        name: busybox
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
    status: {}
    
    kubectl create -f pod.yaml
    

    题5:获取创建命令空间的yaml,但不创建它

    题目:Get the YAML for a new namespace called 'myns' without creating it

    题解:

    kubectl create namespace myns -o yaml --dry-run=client
    
    apiVersion: v1
    kind: Namespace
    metadata:
      creationTimestamp: null
      name: myns
    spec: {}
    status: {}
    

    题6:获取ResourceQuota 的yaml,但不创建它

    题目:Get the YAML for a new ResourceQuota called 'myrq' with hard limits of 1 CPU, 1G memory and 2 pods without creating it

    题解:

    kubectl create quota myrq --hard=cpu=1,memory=1G,pods=2 --dry-run=client -o yaml
    
    apiVersion: v1
    kind: ResourceQuota
    metadata:
      creationTimestamp: null
      name: myrq
    spec:
      hard:
        cpu: "1"
        memory: 1G
        pods: "2
    status: {}
    

    题7:获取所有命名空间上的 pod

    题目:Get pods on all namespaces

    题解:

    kubectl get po -A
    

    题8:创建pod并开发端口

    题目:Create a pod with image nginx called nginx and expose traffic on port 80

    题解:

    kubectl run nginx --image=nginx --port=80
    

    题9:修改pod的镜像,并观察pod

    题目:Change pod's image to nginx:1.7.1. Observe that the container will be restarted as soon as the image gets pulled

    题解:

    kubectl set image pod/nginx nginx=nginx:1.7.1
    kubectl describe po nginx 
    kubectl get po nginx -w 
    
    # 也可以使用kubectl edit 修改yaml中的images值
    

    题10:获取nginx pod的ip

    题目:Get nginx pod's ip created in previous step

    题解:

    kubectl get po -o wide | grep nginx
    # 可以使用awk取ip,不过做题的时候没必要
    

    题11:创建临时pod访问nginx镜像

    题目:use a temp busybox image to wget its '/'

    题解:

    kubectl run busybox --image=busybox --rm -it -- wget -O- {nginx pod的ip}:80
    

    题12:获取pod的yaml

    题目:Get pod's YAML

    题解:

    kubectl get po nginx -o yaml
    

    题13:获取有关 pod 的信息,包括有关潜在问题

    题目:Get information about the pod, including details about potential issues (e.g. pod hasn't started)

    题解:

    kubectl describe po nginx
    

    题14:获取pod的日志

    题目:Get pod logs

    题解:

    kubectl logs nginx
    

    题15:如果 pod 崩溃并重新启动,则获取有关前一个实例的日志

    题目:If pod crashed and restarted, get logs about the previous instance

    题解:

    kubectl logs nginx -p
    

    题16:在pod中执行命令

    题目:Execute a simple shell on the nginx pod

    题解:

    kubectl exec -it nginx -- /bin/sh
    

    题17:创建一个执行一条命令的pod

    题目:Create a busybox pod that echoes 'hello world' and then exits

    题解:

    kubectl run busybox --image=busybox -it -- echo 'hello world'
    

    题18:同17,但创建的是临时pod

    题目:Do the same, but have the pod deleted automatically when it's completed

    题解:

    kubectl run busybox --image=busybox -it --rm -- /bin/sh -c 'echo hello world'
    

    题19:创建一个pod,并设置env

    题目:Create an nginx pod and set an env value as 'var1=val1'. Check the env value existence within the pod

    题解:

    # 创建
    kubectl run nginx --image=nginx --restart=Never --env=var1=val1
    # 检查
    kubectl exec -it nginx -- env
    
  • 相关阅读:
    pandas中expand的作用
    pandas中DataFrame的stack()、unstack()和pivot()方法的对比
    Django在windows下用Apache 部署
    pandas分组统计
    DataFrame中的空值处理
    Django signals 监控模型对象字段值的变化
    django+uwsgi+daphne+supervisor生产环境部署
    Django-Channels使用和部署
    Django使用Channels实现WebSocket的方法
    python 操作es
  • 原文地址:https://www.cnblogs.com/52why/p/15906416.html
Copyright © 2020-2023  润新知