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 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 从你的主终端访问多个集群。把所有这些上下文的名字写进 /opt/course/1/contexts

接下来写一条显示当前环境的命令到 /opt/course/1/context_default_kubectl.sh ,该命令应使用 kubectl

最后写第二条命令做同样的事情到 /opt/course/1/context_default_no_kubectl.sh ,但不使用 kubectl


解答:

k config get-contexts # copy manually
k config get-contexts -o name > /opt/course/1/contexts

Contexts-0

kubectl config current-context
echo "kubectl config current-context" > /opt/course/1/context_default_kubectl.sh
bash /opt/course/1/context_default_kubectl.sh

Contexts-1

cat ~/.kube/config | grep current | awk '{printf $2}'
echo "cat ~/.kube/config | grep current | awk '{printf $2}'" > /opt/course/1/context_default_no_kubectl.sh

Contexts-2


Killer.sh CKA模拟题目 汇总