栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

CKA 模拟题(Configure Access to Multiple Clusters)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CKA 模拟题(Configure Access to Multiple Clusters)

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

alias k=kubectl  
export do="--dry-run=client -o yaml"
export now="--force --grace-period 0"   # k delete pod x $now
# Vim
# To make vim use 2 spaces for a tab edit ~/.vimrc to contain:
set tabstop=2
set expandtab
set shiftwidth=2
Answer

Maybe the fastest way is just to run:

第一步
k config get-contexts # copy manually
k config get-contexts -o name > /opt/course/1/contexts
Or using jsonpath:
k config view -o yaml # overview`` k config view -o jsonpath=“{.contexts[].name}" k config view -o jsonpath="{.contexts[].name}” | tr " " “n” # new lines k config view -o jsonpath=“{.contexts[*].name}” | tr " " “n” > /opt/course/1/contexts `
The content should then look like:

– # /opt/course/1/contexts
k8s-c1-H
k8s-c2-AC
k8s-c3-CCC
Next create the first command:

vim /opt/course/1/context_default_kubectl.sh

写入
kubectl config current-context

➜ sh /opt/course/1/context_default_kubectl.sh
k8s-c1-H

And the second one:
vim /opt/course/1/context_default_no_kubectl.sh
写入
cat ~/.kube/config | grep current
运行
➜ sh /opt/course/1/context_default_no_kubectl.sh
current-context: k8s-c1-H
In the real exam you might need to filter and find information from bigger lists of resources, hence knowing a little jsonpath and simple bash filtering will be helpful.

The second command could also be improved to:

vim /opt/course/1/context_default_no_kubectl.sh
cat ~/.kube/config | grep current | sed -e "s/current-context: //"

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/827629.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号