Kube API for Listing the CustomResource instances in a namespace (or on a cluster) in Kubernetes

1.1k views Asked by At

Using command-line utility kubectl we can list a custom resource instances as follows

kubectl get <customresource_kind>

In a similar fashion, do we have a REST API to achieve the same? i.e. the API takes the Kind of the CustomResource and lists all the instances created?

I am referring to this API Reference : https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/

1

There are 1 answers

0
Nepomucen On

You can list crds like every other API resources using Kubernetes REST API.

The final URL path will differ, depending on object's scope: Cluster or Namespaced.

The general rule for constructing the URL path is described here in official documentation.

Just to give you an example based on calico's 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