KOPS - 2021年12月
type: channel
link: https://www.kops.cc/2021/12/
description: 好记性不如烂笔头，记录学习点滴！https://www.kops.cc。技术交流加微 haxicc
items: CKS 1.22 模拟题
items: CKA 1.22 模拟题

CKS 1.22 模拟题
type: item
date: 2021-12-14T02:44:00+00:00
description: Question 1Task weight: 1%You have access to multiple clusters from your main terminal through kubectl contexts. Write all context names into /opt/course/1/contexts, one per line.From the kubeconfig extract the certificate of user restricted@infra-prod and write it decoded to /opt/course/1/cert.题目解析：考点kubectl解题➜ kubectl config get-contexts -o name > /opt/course/1/contexts # 从 .kube/config 文件中找到 - name: restricted@infra-prod user client-certificate-data: LS0tLS1CRUdJ... ➜ echo LS0tLS1CRUdJ... | base64 -d > /opt/course/1/certQuestion 2Task weight: 4%Use context: kubectl config use-context workload-prodFalco is installed with default configuration on node cluster1-worker1. Connect using ssh cluster1-worker1. Use it to:Find a Pod running image nginx which creates unwanted package management processes inside its container.Find a Pod running image httpd which modifies /etc/passwd.Save the Falco logs for case 1 under /opt/course/2/falco.log in format time,container-id,container-name,user-name. No other information should be in any line. Collect the logs for at least 30 seconds.Afterwards remove the threads (both 1 and 2) by scaling the replicas of the Deployments that control the offending Pods down to 0.题目解析：考点falco解题通过 falco 日志查找容器 ID, PODFind a Pod running image nginx which creates unwanted package management processes inside its container➜ ssh cluster1-worker1 ➜ root@cluster1-worker1:~# grep nginx /var/log/syslog | grep -i "package management process" Dec 13 01:03:23 cluster1-worker1 falco[28640]: 01:03:23.564163340: Error Package management process launched in container (user=root user_loginuid=-1 command=apk container_id=3ed4079e7f61 container_name=nginx image=docker.io/library/nginx:1.19.2-alpine) ... ➜ root@cluster1-worker1:~# crictl ps -id 3ed4079e7f61 CONTAINER ID IMAGE NAME ... POD ID 3ed4079e7f61 6f715d38cfe0e nginx ... 7a864406b9794 ➜ root@cluster1-worker1:~# crictl pods -id 7a864406b9794 POD ID ... NAME NAMESPACE ... 7a864406b9794 ... webapi-6cfddcd6f4-ftxg4 t…

CKA 1.22 模拟题
type: item
date: 2021-12-12T06:54:00+00:00
description: Question 1Task weight: 1%You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts.Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh, the command should use kubectl.Finally write a second command doing the same thing into /opt/course/1/context_default_no_kubectl.sh, but without the use of kubectl.题目解析：考点kubectl, contexts kubectl 概述 | Kubernetes, kubectl-commands解题根据题意：Write all those context names into /opt/course/1/contexts➜ kubectl config get-contexts -o name > /opt/course/1/contexts根据题意：Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh, the command should use kubectl➜ vim /opt/course/1/context_default_kubectl.sh kubectl config current-context根据题意：Finally write a second command doing the same thing into /opt/course/1/context_default_no_kubectl.sh, but without the use of kubectl➜ vim /opt/course/1/context_default_no_kubectl.sh grep "current-context: " ~/.kube/config | awk '{print $2}'Question 2Task weight: 3%Use context: kubectl config use-context k8s-c1-HCreate a single Pod of image httpd:2.4.41-alpine in Namespace default. The Pod should be named pod1 and the container should be named pod1-container. This Pod should only be scheduled on a master node, do not add new labels any nodes.Shortly write the reason on why Pods are by default not scheduled on master nodes into /opt/course/2/master_schedule_reason .题目解析：考点Pod Pods | Kubernetes解题切换上下文➜ kubectl config use-context k8s-c1-H Switched to context "k8s-c1-H".快速生成创建 Pod 的 yaml 模板➜ kubectl run pod1 --image=httpd:2.4.41-alpine --dry-run=client -o yaml > 2.yaml根据题意，修改模板➜ vim 2.yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: pod1 name: pod1 spec: containers: - image: httpd:2.4.41-alpine name: pod1-container # 修改, the container should be named `pod1-container` resources: {} dnsPolicy: ClusterFirst restartPolicy:…