考试内容
Important Instructions: CKA and CKAD
- 考试包括 15-20 项performance-based tasks。
- 实测是17道题
- 考生有 2 小时的时间完成 CKA 和 CKAD 考试。
- 因为从06/2022开始环境升级(贬义),考试环境更难用了,变的很卡,所以时间变得比较紧张。容易做不完题,建议先把有把握的,花费时间不多的题先做掉
- CKS CKA CKAD changed Terminal to Remote Desktop
- 2022.9更新,据说很多卡顿的bug已经修复。
- 因为从06/2022开始环境升级(贬义),考试环境更难用了,变的很卡,所以时间变得比较紧张。容易做不完题,建议先把有把握的,花费时间不多的题先做掉
- 2020年9月更新的CKA新版考试66分以上即可通过(原定72分),考试不通过有一次补考机会。
CKA Preparation
- Read the Curriculum
https://github.com/cncf/curriculum - Read the Handbook
https://docs.linuxfoundation.org/tc-docs/certification/If-candidate-handbook - Read the important tips
https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad - Read the FAQ
https://docs.linuxfoundation.org/tc-docs/certification/faq-cka-ckad
如何备考
k8s练习环境
本地环境-Minikube
可以本地安装Minikube
练习, 参考另一篇博客Minikube安装-MacOS M1。
在线环境-killercoda
- k8s 环境: https://killercoda.com/playgrounds/scenario/kubernetes
- CKA在线练习环境:https://killercoda.com/killer-shell-cka
- CKAD在线练习环境:https://killercoda.com/killer-shell-ckad
- CKS在线练习环境:https://killercoda.com/killer-shell-cks
CKA课程
- 【需付费】CKA考试-对应官方课程Kubernetes Fundamentals (LFS258)
- 【需付费】Udemy CKA 课程
- Certified Kubernetes Administrator (CKA) – KodeKloud – by Mumshad Mannambeth)
- Certified Kubernetes Administrator (CKA) with Practice Tests – by Mumshad Mannambeth – Udemy
- 【需付费】Oreilly视频课程: (For beginner or Advanced) Certified Kubernetes Administrator (CKA), 2nd Ed.
经验总结
- 经验1: 不要完全按照顺序做题!!!Kubernates cluster upgrade 或者 etcd backup 放最后做,否则环境搞坏,其他的题不能做. 隔过去的题可以用flag标记,省的忘记哪些还没有做。
- 经验2: 需要在ssh到新的node的时候,在新的tab做题,避免忘记exit出来。
- 使用
kubectl explain
来查看命令内容, 例如kubectl explain pods.spec.tolerations --recursive
- 使用
kubectl --help
或kubectl -h
查看命令参数, 例如kubectl create clusterrole --help
- 使用
kubectl api-resources
, 查看所有资源缩写 - 考试环境点击
-
来zoom out, 这样可以显示更多内容。(尤其是使用平板电脑,屏幕太小,显示有效内容很少)。 - 善用考试记事本(exam notepad)。
- 复制粘贴
- What always works: copy+paste using right mouse context menu
- What works in Terminal: Ctrl+Shift+c and Ctrl+Shift+v
- What works in other apps like Firefox: Ctrl+c and Ctrl+v
- 可以用Tab键,自动补全kubectl命令,大大提升效率,以及避免键盘输入拼写错误
- 考试时间快结束的时候,弹出对话框,问你是否结束考试,一定要点击"Continue"继续考试
- 否则直接结束考试,会引发考试系统的bug: session未能正常close,造成一直无法出成绩。只能通过提ticket来人工解决,才能拿到成绩。
常用官方文档链接
- https://kubernetes.io/docs/reference/kubectl/cheatsheet/
- https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
- https://github.com/kubernetes/kubernetes
- 考试中多使用命令式命令CLI ( imperative commands),少使用声明式(Declarative)
- https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
- https://medium.com/better-programming/kubernetes-tips-create-pods-with-imperative-commands-in-1-18-62ea6e1ceb32
- Promote the use of generators for Job, CronJob, Network Policies etc: this link is very useful:
- Use maximum conventions and best practices to avoid unexpected pod errors:
Pre Setup
Once you’ve gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these:
kubectl 设置
1. 设置kubectl命令别名
1 | alias k=kubectl # will already be pre-configured |
1 | # 使用例子 |
Alias Namespace
In addition you could define an alias like:
1 | alias kn='kubectl config set-context --current --namespace |
Which allows you to define the default namespace of the current context. Then once you switch a context or namespace you can just run:
1 | kn default # set default to default |
But only do this if you used it before and are comfortable doing so. Else you need to specify the namespace for every call, which is also fine:
1 | k -n my-namespace get all |
如果想使用不同的shell
或tmux
,可以把这些 alias和变量存入~/.bashrc
.
2. 开启自动补全autocomplete
(2022最新考试环境默认已开启,不用再配置了)
kubectl --help | grep bash
,此步是为了找关键词completionsudo vim /etc/profile
- 添加
source <(kubectl completion bash)
- 保存退出,
source /etc/profile
Vim 设置
复制粘贴 - 从网页上copy yaml内容,使用vim 来粘贴时,yaml内容格式会乱。现在考试环境已经被修复,.vimrc
里面默认加了一些vim粘贴的设置。
Make sure to set these in your
.vimrc
or otherwise indents will be very messy during pasting (the exams have these config settings now also by default, but can’t hurt to be able to type them down):
下面代码中,双引号开始的行表示注释。
1 | "1.1 use spaces for tab 由于 Tab 键在不同的编辑器缩进不一致,该设置自动将 Tab 转为空格。 |
Save and close the file by pressing Esc followed by :x and Enter.
Whenever you open Vim now as the current user, these settings will be used.
If you ssh onto a different server, these settings will not be transferred.
1.3 Indent multiple lines
To indent multiple lines press Esc and type :set shiftwidth=2
.
First mark multiple lines using Ctrl v and the up/down keys. Then to indent the marked lines press > or <. You can then press . to repeat the action.
1.4 Get used to copy/paste/cut with vim:
1 | Mark lines: Esc+v (then arrow keys) |
1.5 :set paste
:set nopaste
Turning off auto indent when pasting text into vim:set paste
Turning on auto indent when pasting text into vim
Paste toggle
1.6 显示行号 :set number
toggle vim line numbers
When in vim
you can press Esc and type :set number
(turn on number) or :set nonumber
(turn off number) followed by Enter to toggle line numbers. This can be useful when finding syntax errors based on line - but can be bad when wanting to mark© by mouse.
You can also just jump to a line number with Esc :22
+ Enter.
Vim基本操作
使用nano编辑器
1 | # 编辑1.yaml文件,如果1.yaml文件不存在则新建 |
考题1-RBAC
RBAC题目
Task weight: 4%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k8s |
Context
You have been asked to create a new ClusterRole
for a deployment pipeline and bind it to a specific ServiceAccount
scoped to a specific namespace.
Task
Create a new ClusterRole
named deployment-clusterrole
which only allows to create the following resource types:
- Deployment
- StatefulSet
- DaemonSet
Create a new ServiceAccount
named cicd-token
in the existing namespace app-team1
.
Bind the new ClusterRole deployment-clusterrole
to the new ServiceAccount cicd-token
, limited to the namespace app-team1
.
RBAC解答
1 | kubectl config use-contex t k8s |
考题2-创建 NetworkPolicy
题目:NetworkPolicy
Task weight: 7%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context hk85 |
Task
Create a new NetworkPolicy
named allow-port-from-namespace
that allows Pods in the existing
namespace internal
to connect to port 5768
of other Pods in the namespace my-app
.
Ensure that the new NetworkPolicy:
- does not allow access to Pods not listening on port 5768
- does not allow access from Pods not in namespace
internal
解答:NetworkPolicy
1 | kubectl config use-context hk8s |
1 | apiVersion: networking.k8s.io/v1 |
1 | kubectl apply -f allow-port-from-namespace.yaml |
考题3-创建 svc
题目:创建 svc
Task weight: 7%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k8S |
Task
Reconfigure the existing deployment front-end
and add a port specification named http
exposing port 80/tcp
of the existing container nginx
.
Create a new service named front-end-svc
exposing the container port http
.
Configure the new service to also expose the individual Pods via a NodePort
on the nodes on which they are scheduled.
解答:创建 svc
search “containerPort”, 参考Connecting Applications with Services
configure-pod-container
1 | kubectl config use-context k8S |
1 | spec: |
1 | kubectl expose deployment front-end --name=front-end-svc --port=80 --target-port=80 --protocol=TCP --type=NodePort |
考题4-创建 ingress 资源
题目:ingress
Task weight: 7%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k85 |
Task
Create a new nginx Ingress resource as follows:
- Name:
pong
- Namespace:
ing-internal
- Exposing service
hi
on path/hi
using service port5678
The availability of service
hi
can be checked using the following command, which should returnhi
:
[student@node-11 $ curl -kl <INTERNAL_IP>/hi
解答:ingress
参考ingress
1 | kubectl config use-context k85 |
1 | apiVersion: networking.k8s.io/v1 |
1 | kubectl apply -f pong.yaml |
1 | # 方法2 |
考题5-扩展 deployment
题目:扩展 deployment
Task weight: 4%
难易程度: 简单
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k8s |
Task
Scale the deployment loadbalancer
to 6
pods.
解答:扩展 deployment
1 | $ kubectl scale deployment loadbalancer --replicas=6 |
考题6-将 pod 部署到指定 node 节点上
题目:将 pod 部署到指定 node 节点上
难易程度: 简单
Task weight: 4%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k8s |
Task
Schedule a pod as follows:
- Name:
nginx-kuSc00401
- Image:
nginx
- Node selector:
disk=spinning
解答:将 pod 部署到指定 node 节点上
参考官方文档: Assigning Pods to Nodes
1 | kubectl config use-context k8s |
1 | apiVersion: v1 |
1 | kubectl apply -f nginx-kusc00401.yaml |
考题7-Kubernates-upgrade
题目: Kubernates-upgrade
Task weight: 7%
Set configuration context:
1 | [student@node -1] $ kubectl config use-context mk85 |
Task
Given an existing Kubernetes cluster running version 1.24.1
, upgrade all of the Kubernetes control plane and node components on the master node only to version 1.24.2
.
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.
解答:升级master
参考官方文档: kubernetes-upgrade kubeadm
1 | $ kubectl config use-context mk8s |
考题8-etcd 备份还原
题目:etcd 备份还原
(1.20 版本需要把端口号从 2739 改成 2830)
Task weight: 7%
No configuration context change required for this item.
Task
First, create a snapshot of the existing etc
instance running at https://127.0.0.1:2379
, saving the snapshot to /srv/data/etcd-snapshot.db
.
Creating a snapshot of the given instance is expected to complete in seconds.
If the operation seems to hang, something’s likely wrong with your command. Use CTRL+ C to cancel the operation and try again.
Next, restore an existing, previous snapshot located at
/var/lib/backup/etcd-snapshot-previous.db
.
The following TLS certificates/key are supplied for
connecting to the server withetcdctl
:
- CA certificate:
/opt/KUIN00601/ca.crt
- Client certificate:
/opt/KUIN00601/etcd-client.crt
- Client key:
/opt/KUIN00601/etcd-client.key
解答
Search etcd backup
, 选择 Operating etcd clusters for Kubernetes
1 | # 1 backup |
1 | # /etc/kubernetes/manifests/etcd.yaml |
1 | ### 1.0.2 [本题目中无需这一步] 或者1.0.1可用1.0.2取代 |
1 | # /etc/kubernetes/etcd.yaml |
1 | ## 2.4 |
考题9-创建多个 container 的 Pod
题目:创建多个 container 的 Pod
难易程度: 简单
Task weight: 4%
Set configuration context:
1 | [student@node-1] $ kubectl config use-context k8s |
Task
Create a pod named kucc1
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
.
解答:创建多个 container 的 Pod
1 | kubectl config use-context k8s |
1 | apiVersion: v1 |
1 | kubectl apply -f kucc1.yaml |
考题10-创建 Persistent Volume
题目:创建 Persistent Volume
Task weight: 4%
Set configuration context:
[student@node-1] $ kubectl config use-context hk85
Task
Create a persistent volume with name app-config
, of capacity 2Gi
and access mode ReadWriteMany
. The type of volume is
hostPath
and its location is /srv/app-config
.
解答:创建 Persistent Volume
参考官方文档: example of hostPath typed volume
1 | kubectl config use-context hk85 |
1 | apiVersion: v1 |
1 | kubectl apply -f app-config.yaml |
考题11-创建 PVC
题目:创建 PVC
Task weight: 7%
Set configuration context:
[student@node-1] $ kubectl config use-context ok85
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.
解答:创建 PVC
参考官方文档:
- 搜索
PV pod
, 选择"Configure a Pod to Use a PersistentVolume for Storage | Kubernetes" - 搜索
kubectl edit pvc
Resizing Persistent Volumes using Kubernetes
1 | kubectl config use-context hk85 |
1 | apiVersion: v1 |
1 | kubectl apply -f pv-volume.yaml |
1 | apiVersion: v1 |
1 | kubectl apply -f web-server.yaml |
考题12-设置node unavailable
题目:设置node unavailable
Task weight: 4%
难易程度: 简单
Set configuration context:
1 | [student@node-1] $ kubectl config use-context ek85 |
Task
Set the node named ek8s-node-1
as unavailable and reschedule all the pods running on it.
解答:设置node unavailable
1 | kubectl config use-context ek85 |
考题13-监控 pod 的日志
题目:监控 pod 的日志
难易程度: 简单
Task weight: 5%
Set configuration context:
[student@node-1] $ kubectl config use-context k8s
Task
Monitor the logs of pod foobar
and:
- Extract log lines corresponding to error
unable-to-access-website
- Write them to
/opt/KUTR00101/foobar
解答:监控 pod 的日志
1 | kubectl config use-context k8s |
考题14-查看最高 CPU 使用率的 Pod
题目:查看最高 CPU 使用率的 Pod
Task weight: 5%
难易程度: 简单
Set configuration context:
[student@node-1] $ kubectl config use-context k8s
Task
From the pod label name=cpu-user
, find pods running high CPU workloads and write the name of the pod consuming most
CPU to the file /opt/KUTR00401/KUTR00401.txt
(which already exists).
解答:查看最高 CPU 使用率的 Pod
1 | kubectl top pod -l name=cpu-user -A --sort-by=cpu |
考题15-集群故障排查
题目:集群故障排查
Task weight: 13%
Set configuration context:
[student@node-1] $ kubectl config use-context wk8s
Task
A Kubernetes worker node, named wk8s-node-O
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.
解答:集群故障排查
Search systemctl restart
, 选择Troubleshooting kubeadm
1 | kubectl get nodes |
考题16-添加 sidecar container
题目:添加 sidecar container
Task weight: 7%
Set configuration context:
[student@node-1] $ kubectl config use-context k8s
Context
Without changing its existing containers, an existing Pod needs to be integrated into Kubernetes’s built-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 legacy-app
. The new sidecar container has to run the following command:
/bin/sh -c tail -n+l -f /var/log/legacy-app.log
Use a volume mount named logs
to make the file /var/log/legacy-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/legacy-app.log
解答:添加 sidecar container
官网Search Logging
, 选择Logging Architecture.
1 | kubectl config use-context k8s |
1 | apiVersion: v1 |
1 | # 删除legacy-app,否则再运行yaml时会提示legacy-app已存在 |
考题17-检查有多少 node 节点是健康状态
题目:检查有多少 node 节点是健康状态
Task weight: 4%
Set configuration context:
1 | [studentfnode-1] $ kubectl config use-context k8S |
Task
Check to see how many nodes are ready (not including nodes tainted NoSchedule
) and write the number to /opt/KUSC00402/kusc00402.txt
解答:检查有多少 node 节点是健康状态
Search Check to see how many nodes are ready
, 选择Troubleshooting Clusters
1 | kubectl config use-context k8s |
参考文章
- linux nano命令_Nano入门指南,Linux命令行文本编辑器
- CKS CKA CKAD changed Terminal to Remote Desktop since 06/2022
- 2022年CKA 考试题 2022年3月1日刚过
- 2022.2 k8s-cka考试题库
- CKA 百度文库
- CKA Kubernauts Training Plan Mind 脑图
惊!2020年CKA考试最新最全指南 - 如何在 K8S CKA、CKS 认证中失败!请仔细阅读,风险自负
- 新版本 CKA 资源目录总览