题干
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
奇怪的是居然检查不通过