Task 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.


译文

任务权重:1

你可以通过终端使用 kubectl 访问多个集群。把所有的上下文名称写进 /opt/course/1/contexts ,每行一个。

从 kubeconfig 中提取用户 restricted@infra-prod 的证书,并将其解码后写入 /opt/course/1/cert


解答

把所有集群名字写入文件

k config get-contexts
k config get-contexts -o name > /opt/course/1/contexts
或者
k config view -o jsonpath="{.contexts[*].name}" | tr " " "\n" > /opt/course/1/contexts

用户信息

k config view --raw -ojsonpath="{.users[*].name}" # 查看有哪些用户信息
k config view --raw -ojsonpath="{.users[2].user.client-certificate-data}" | base64 -d > /opt/course/1/cert

#或者直接使用命令
k config view --raw -ojsonpath="{.users[?(.name == 'restricted@infra-prod')].user.client-certificate-data}" | base64 -d > /opt/course/1/cert

file

file