2021年12月

注意:文中代码块会出现很多 \- 这样的字符,实际上是 -,是因为网站的 markdown 渲染有问题,不得不这样写

Question 1

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.

题目解析:

  • 考点

    • kubectl
  • 解题

    ➜ kubectl config get-contexts -o name > /opt/course/1/contexts
    
    # 从 .kube/config 文件中找到
    \- name: restricted@infra-prod
      user
        client-certificate-data: LS0tLS1CRUdJ...
    ➜ echo LS0tLS1CRUdJ... | base64 -d > /opt/course/1/cert

- 阅读剩余部分 -

注意:文中代码块会出现很多 \- 这样的字符,实际上是 -,是因为网站的 markdown 渲染有问题,不得不这样写

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

题目解析:

  • 考点

  • 解题

    • 根据题意: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 use kubectl

      ➜ 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 of kubectl

      ➜ vim /opt/course/1/context_default_no_kubectl.sh
      grep "current-context: " ~/.kube/config | awk '{print $2}'

- 阅读剩余部分 -