用于在Kubernetes中的名称空间或集群中列出CustomResource实例的Kube API

问题描述

使用命令行实用程序kubectl,我们可以如下列出自定义资源实例

kubectl get <customresource_kind>

以类似的方式,我们是否有实现相同的REST API?即该API采用了CustomResource的种类并列出了所有创建的实例?

我指的是此API参考: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/

解决方法

您可以使用Kubernetes REST API像其他所有API资源一样列出crd。

最终的URL路径会有所不同,具体取决于对象的范围:ClusterNamespaced

在官方文档中here描述了构造URL路径的一般规则。

仅举一个基于印花布的clusterinformations.crd.projectcalico.org (v1)的示例:

kubectl proxy --port=8080 &

curl http://localhost:8080/apis/crd.projectcalico.org/v1/clusterinformations | jq '.items[].metadata.name

"default" <- I have only one instance of this type of custom resource

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...