kubectl:描述持久卷声明的注解

kubectl: describe annotations for persistent volume claims

kubectl 的新手。我的任务是生成一份报告(通过 bash 脚本),该报告从持久卷声明 (PVC) 中检索特定注释,但我遇到了麻烦。

据我所知,至少有 1 个注释描述了 PVC 是否由 Velero 备份。此注释存储在 PVC 中。

伪代码是这样的:

Foreach Cluster in ClusterList
    Obtain its kubeconfig file
    Foreach Namespace in AllNamespaces
        Print out Cluster, Namespace, PVC name, Annotation (containing search term)

我可以轻松遍历每个集群并获取其 kubeconfig 文件。 我使用 kubectl describe namespaces 在每个集群中获取该列表。

当我遍历持久卷声明时,在输出中有 13 个键值对 kubectl describe persistentvolumeclaims。我只对 2 个键值感兴趣:NameAnnotations。在这些注释中,我正在查看是否存在“velero”一词。

我尝试应用其他命令和标志但收效甚微:

还有哪些方法?

如果输出显示不存在 PVC,我很好。其实是很好的信息,可以举报

似乎是在用 describe sub-command 追逐红鲱鱼。注释输出是隐藏的元数据,可以使用 -o 标志通过 kubectl get 访问。例如:

kubectl get persistentvolumeclaims -o json

并且可以通过将输出管道输出到 jq

来进一步解析