CKA 1.22 模拟题
Question 1
Task 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 usekubectl
.Finally write a second command doing the same thing into
/opt/course/1/context_default_no_kubectl.sh
, but without the use ofkubectl
.
题目解析:
考点
- 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 usekubectl
➜ 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 ofkubectl
➜ vim /opt/course/1/context_default_no_kubectl.sh grep "current-context: " ~/.kube/config | awk '{print $2}'