新版CKA考试已于2020年9月1日正式上线!
考试模式:线上考试
考试时间:2小时
认证有效期:3年
软件版本:Kubernetes v1.19
重考政策:可接受1次重考
经验水平:中級
题目数量:17题
题库量小:随机的题目重复率极高
考试时可打开两个浏览器Tab,一个是考试窗口,一个用来查阅官方文档](https://kubernetes.io/docs/)
01 Task - 英文
Create a new ClusterRole named deployment-clusterrole that only allows the creation of the following resource types:
-
Deployment
-
StatefulSet
-
DaemonSet
Create a new ServiceAccount named cicd-token in the existing namespace app-team1.
Limited to namespace app-team1, bind the new ClusterRole deployment-clusterrole to the new ServiceAccount cicd-token.kubectl create ns app-team1 kubectl create serviceaccount cicd-token -n app-team1 kubectl create clusterrole deployment-clusterrole --verb=create --resource=deployment,statefulset,daemonset
#limted to the namespace app-team1。需要限制的是namespace级别,clusterrolebinding为设置全局,rolebinding正确 kubectl create rolebinding cicd-clusterrole --clusterrole=deployment-clusterrole --serviceaccount=app-team1:cicd-token
02 Task - 英文
Set the node named ek8s-node-1 as unavaliable and reschedule all the pods running on it.
1kubectl cordon ek8s-node-1 2kubectl drain ek8s-node-1 --delete-local-data --ignore-daemonsets --force
03 Task - 英文
Given an existing Kubernetes cluster running version 1.18.8,upgrade all of Kubernetes control plane and node components on the master node only to version 1.19.0。
You are also expected to upgrade kubelet and kubectl on the master node。
Be sure to drain the master node
before upgrading it and uncordon it after the upgrade.
Do not upgrade the worker nodes,etcd,the container manager,the CNI plugin,the DNS service or any other addons.
1apt update 2apt-cache policy kubeadm 3apt-get update && apt-get install -y --allow-change-held-packages kubeadm=1.19.0 4kubeadm version #检查kubeadm版本 5kubectl drain master --ignore-daemonsets --delete-local-data --force #腾空控制平面节点 6sudo kubeadm upgrade plan # 命令查看可升级的版本信息 7sudo kubeadm upgrade apply v1.19.0 --etcd-upgrade=false #查看版本信息时,排除etcd从3.4.3-0升到3.4.7-0 8kubectl uncordon master 9sudo kubeadm upgrade node #升级其他控制面节点 10apt-get update && apt-get install -y --allow-change-held-packages kubelet=1.19.0 kubectl=1.19.0 11#升级其他控制面节点 12sudo systemctl daemon-reload 13sudo systemctl restart kubelet
04 Task - 中文
首先,为运行在https://127.0.0.1:2379 上的现有etcd 实例创建快照并将快照保存到/data/backup/etcd-snapshot.db。
为给定实例创建快照预计能在几秒钟内完成。如果该操作似乎挂起,则命令可能有问题。用ctrl+c 来取消操作,然后重试。
然后还原位于/var/data/etcd-snapshot-previous.db的现有先前快照。
提供了以下TLS证书和密钥,以通过etcdctl连接到服务器。
- ca证书:/opt/KUIN00601/ca.crt
- 客户端证书:/opt/KUIN00601/etcd-client.crt
- 客户端密钥:/opt/KUIN00601/etcd-client.key
1ETCDCTL_API=3 etcdctl --endpoint=https://127.0.0.1:2379 --cert-file=/opt/KUIN00601/etcd-client.crt --key-file=/opt/KUIN00601/etcd-client.key --ca-file=/opt/KUIN00601/ca.crt snapshot save /data/backup/etcd-snapshot.db 2 3ETCDCTL_API=3 etcdctl --endpoint=https://127.0.0.1:2379 --cert-file=/opt/KUIN00601/etcd-client.crt --key-file=/opt/KUIN00601/etcd-client.key --ca-file=/opt/KUIN00601/ca.crt snapshot restore /var/data/etcd-snapshot-previous.db
05 Task - 英文
Create a new NetworkPolicy named allow-port-from-namespace to allow Pods in the existing namespace internal to connect to port 8080 of other Pods in the same namespace.
Ensure that the new NetworkPolicy:
-
does not allow access to Pods not listening on port 8080.
-
does not allow access from Pods not in namespace internal.
#network.yaml apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-port-from-namespace namespace: internal spec: podSelector: matchLabels: {
} policyTypes:
- Ingress ingress:
- from:
- podSelector: {
} ports: - protocol: TCP port: 8080 #spec.podSelector限定了这个namespace里的pod可以访问 kubectl create -f network.yaml
06 Task - 英文
Reconfigure the existing deployment front-end and add a port specifiction named http exposing port 80/tcp of the existing container nginx.
Create a new service named front-end-svc exposing the container prot http.
Configure the new service to also expose the individual Pods via a NodePort on the nodes on which they are scheduled.
1kubectl get deploy front-end 2kubectl edit deploy front-end -o yaml 3#port specification named http 4#service.yaml 5apiVersion: v1 6kind: Service 7metadata: 8 name: front-end-svc 9 labels: 10 app: nginx 11spec: 12 ports: 13 - port: 80 14 protocol: tcp 15 name: http 16 selector: 17 app: nginx 18 type: NodePort 19# 20kubectl create -f service.yaml 21# 22kubectl get svc 23 24#或者一条命令搞定,注意会遗漏port specification named http 25kubectl expose deployment front-end --name=front-end-svc --port=80 --tarport=80 --type=NodePort
07 Task - 英文
Create a new nginx Ingress resource as follows:
- Name: ping
- Namespace: ing-internal
- Exposing service hi on path /hi using service port 5678
The avaliability of service hi can be checked using the following command,which should return hi:
curl -kL /hi
1vi ingress.yaml 2# 3apiVersion: networking.k8s.io/v1 4kind: Ingress 5metadata: 6 name: ping 7 namespace: ing-internal 8spec: 9 rules: 10 - http: 11 paths: 12 - path: /hi 13 pathType: Prefix 14 backend: 15 service: 16 name: hi 17 port: 18 number: 5678 19# 20kubectl create -f ingress.yaml
08 Task - 英文
Scale the deployment presentation to 3 pods.
1kubectl get deployment 2kubectl scale deployment.apps/presentation --replicas=3
09 Task - 英文
Task
Schedule a pod as follows:
-
name: nginx-kusc00401
-
Image: nginx
-
Node selector: disk-spinning
#yaml apiVersion: v1 kind: Pod metadata: name: nginx-kusc00401 spec: containers:
- name: nginx image: nginx imagePullPolicy: IfNotPresent nodeSelector: disk: spinning
kubectl create -f node-select.yaml
10 Task - 英文
Task
Check to see how many nodes are ready (not including nodes tainted NoSchedule)and write the number to /opt/KUSC00402/kusc00402.txt.
1kubectl describe nodes | grep ready|wc -l 2kubectl describe nodes | grep -i taint | grep -i noschedule |wc -l 3echo 3 > /opt/KUSC00402/kusc00402.txt 4 5# 查询集群Ready节点数量 6kubectl get node | grep -i ready |wc -l 7# 找出节点taints、noSchedule 8kubectl describe nodes | grep -i taints | grep -i noschedule |wc -l 9#将得到的减数,写入到文件 10echo 2 > /opt/KUSC00402/kusc00402.txt
11 Task - 英文
Create a pod named kucc8 with a single app container for each of the following images running inside (there may be between 1 and 4 images specified):
nginx + redis + memcached + consul .
1kubectl run kucc8 --image=nginx --dry-run -o yaml > kucc8.yaml 2# vi kucc8.yaml 3apiVersion: v1 4kind: Pod 5metadata: 6 creationTimestamp: null 7 name: kucc8 8spec: 9 containers: 10 - image: nginx 11 name: nginx 12 - image: redis 13 name: redis 14 - image: memcached 15 name: memcached 16 - image: consul 17 name: consul 18# 19kubectl create -f kucc8.yaml 20#12.07
12 Task - 英文
Task
Create a persistent volume whit name app-config, of capacity 1Gi and access mode ReadOnlyMany . the type of volume is hostPath and its location is /srv/app-config .
1#vi pv.yaml 2apiVersion: v1 3kind: PersistentVolume 4metadata: 5 name: app-config 6spec: 7 capacity: 8 storage: 1Gi 9 accessModes: 10 - ReadOnlyMany 11 hostPath: 12 path: /srv/app-config 13# 14kubectl create -f pv.yaml
13 Task - 英文
Task
Create a new PersistentVolumeClaim:
- Name: pv-volume
- Class: csi-hostpath-sc
- Capacity: 10Mi
Create a new Pod which mounts the PersistentVolumeClaim as a volume:
- Name: web-server
- Image: nginx
- Mount path: /usr/share/nginx/html
Configure the new Pod to have ReadWriteOnce access on the volume.
Finally,using kubectl edit or Kubectl patch expand the PersistentVolumeClaim to a capacity of 70Mi and record that change.
1vi pvc.yaml 2#使用指定storageclass创建一个pvc 3apiVersion: v1 4kind: PersistentVolumeClaim 5metadata: 6 name: pv-volume 7spec: 8 accessModes: 9 - ReadWriteOnce 10 volumeMode: Filesystem 11 resources: 12 requests: 13 storage: 10Mi 14 storageClassName: csi-hostpath-sc 15 16# vi pod-pvc.yaml 17apiVersion: v1 18kind: Pod 19metadata: 20 name: web-server 21spec: 22 containers: 23 - name: web-server 24 image: nginx 25 volumeMounts: 26 - mountPath: "/usr/share/nginx/html" 27 name: my-volume 28 volumes: 29 - name: my-volume 30 persistentVolumeClaim: 31 claimName: pv-volume 32# craete 33kubectl create -f pod-pvc.yaml 34#edit 修改容量 35kubectl edit pvc pv-volume --record
14 Task - 英文
Task
Monitor the logs of pod bar and:
-
Extract log lines corresponding to error unable-to-access-website
-
Write them to /opt/KUTR00101/bar
kubectl logs bar | grep 'unable-to-access-website' > /opt/KUTR00101/bar cat /opt/KUTR00101/bar
15 Task - 英文
Context
Without changing its existing containers,an existing Pod needs to be integrated into Kubernetes’s build-in logging architecture (e.g. kubectl logs). Adding a streaming sidecar container is a good and common way to accomplish this requirement.
Task
Add a busybox sidecar container to the existing Pod big-corp-app. The new sidecar container has to run the following command:
/bin/sh -c tail -n+1 -f /var/log/big-corp-app.log
Use a volume mount named logs to make the file /var/log/big-corp-app.log available to the sidecar container.
Don’t modify the existing container.
Don’t modify the path of the log file,both containers must access it at /var/log/big-corp-app.log.
1# 2kubectl get pod big-corp-app -o yaml 3# 4apiVersion: v1 5kind: Pod 6metadata: 7 name: big-corp-app 8spec: 9 containers: 10 - name: big-corp-app 11 image: busybox 12 args: 13 - /bin/sh 14 - -c 15 - > 16 i=0; 17 while true; 18 do 19 echo "$(date) INFO $i" >> /var/log/big-corp-app.log; 20 i=$((i+1)); 21 sleep 1; 22 done 23 volumeMounts: 24 - name: logs 25 mountPath: /var/log 26 - name: count-log-1 27 image: busybox 28 args: [/bin/sh, -c, 'tail -n+1 -f /var/log/big-corp-app.log'] 29 volumeMounts: 30 - name: logs 31 mountPath: /var/log 32 volumes: 33 - name: logs 34 emptyDir: { 35 36 } 37 38#验证: 39kubectl logs big-corp-app -c count-log-1
16 Task - 英文
Form the pod label name-cpu-loader,find pods running high CPU workloads and write the name of the pod consuming most CPU to the file /opt/KUTR00401/KURT00401.txt(which alredy exists).
查看Pod标签为name=cpu-user-loader 的CPU使用率并且把cpu使用率最高的pod名称写入/opt/KUTR00401/KUTR00401.txt文件里
1kubectl top pods -l name=name-cpu-loader --sort-by=cpu 2echo '排名第一的pod名称' >>/opt/KUTR00401/KUTR00401.txt
17 Task - 英文
Task
A Kubernetes worker node,named wk8s-node-0 is in state NotReady .
Investigate why this is the case,and perform any appropriate steps to bring the node to a Ready state,ensuring that any changes are made permanent.
Yon can ssh to teh failed node using:
ssh wk8s-node-oYou can assume elevated privileges on the node with the following command:
sudo -i
1#名为wk8s-node-1 的节点处于NotReady状态,将其恢复成Ready状态,并且设置为开机自启 2# 连接到NotReady节点 3ssh wk8s-node-0 4#获取权限 5sudo -i 6# 查看服务是否运行正常 7systemctl status kubelet 8#如果服务非正常运行进行恢复 9systemctl start kubelet 10#设置开机自启 11systemctl enable kubelet