ckad认证考题-核心概念
Posted 极速快码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于ckad认证考题-核心概念的主要内容,如果未能解决你的问题,请参考以下文章
JAVA面试都有Spring考题,还有必要去考Spring认证(证书)吗?
Kubernetes CKAD 1.20 - 真题 (第1题)