本文主要是介绍【CKA模拟题】学会JSONPath,精准定位Pod信息!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
you have a script named pod-filter.sh . Update this script to include a command that filters and displays the label with the value application of a pod named nginx-pod using jsonpath only.
您有一个名为pod-filter.sh的脚本。更新此脚本以包含一个命令,该命令仅使用jsonpath过滤并显示名为
nginx-pod
的pod的值application
的标签。
解题思路
- 切换K8S集群环境ca
kubectl config use-context kubernetes-admin@kubernetes
- 按要求编写脚本
#!/bin/bashread -p "Enter the Pod name you want to filter: " pod_namekubectl get pods -o=jsonpath='{range .items[?(@.metadata.name=="'"$pod_name"'")]}{.metadata.labels.application}{"\n"}{end}'
- 赋予脚本的执行权限,并执行。
controlplane $ chmod +x pod-filter.sh
controlplane $ ./pod-filter.sh
Enter the Pod name you want to filter: nginx-pod
frontend
奇怪的是居然检查不通过
这篇关于【CKA模拟题】学会JSONPath,精准定位Pod信息!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!