How To: List the Namespaces for a Kubernetes Cluster
  • 04 Sep 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light

How To: List the Namespaces for a Kubernetes Cluster

  • Dark
    Light

Article summary

After deploying the RealTheory collector to a Kubernetes cluster (See Installing RealTheory in a Cluster), the cluster and its associated objects become available in the RealTheory API within minutes.

Get Namespaces

To get the list of available namespaces for a given cluster, call the method below on the K8sSummary endpoint.

GET <endpoint>/theory/api/v1/k8ssummary/namespacesummaries/search/query/{query}?index={index}&count={count}&order={order}&direction={direction}

where

  • {endpoint} - is the URL of the RealTheory SaaS portal for your account.
  • {query} - is a query used to limit the results to namespaces for a given cluster.
  • {index} - is the starting index of the namespace summaries to include in the list. This parameter is optional and defaults to 0 if not specified.
  • {count} - is maximum number of namespace summaries to return. This parameter is optional and defaults to 100 if not specified.
  • {order} - is a string containing the name of the attribute to sort on. This parameter is optional.
  • {direction} - is a number that controls the direction of the sort. A value equal to or greater than 0 indicates ascending order; a value less than 0 indicates descending order. This parameter is optional and defaults to 0 if not specified.

Note: All calls to RealTheory APIs must be authenticated and authorized. See Authentication for more details.

Example

GET theory/api/v1/k8ssummary/namespacesummaries/search/query/metadata.clusterName=realtheory-cluster-01?index=0&count=100&order=metadata.name&direction=0

which returns a list of the first 100 namespace summaries associated with cluster realtheory-cluster-01, sorted by name in ascending order.

Notes:

  • A namespace summary is an object that summarizes key information related to a Kubernetes namespace.
  • The query should be URL encoded; otherwise the request might be rejected.

Output

Returns an array of NamespaceSummary objects:

[
  {
    "metadata": {
      "id": "3fa272eb-7faa-41f2-a416-2c59b950b277",
      "name": "cert-manager",
      "clusterId": "f99e055f-b35d-208b-63b1-f4222b80151a",
      "clusterName": "realtheory-cluster-01",
      "owners": null,
      "timestamp": "2024-03-06T20:17:25.0471704Z"
    },
    ...
  },
  {
    "metadata": {
      "id": "b1cb1122-68e6-41f8-bd62-8b6e2ba675cd",
      "name": "default",
      "clusterId": "f99e055f-b35d-208b-63b1-f4222b80151a",
      "clusterName": "realtheory-cluster-01",
      "owners": null,
      "timestamp": "2024-03-06T20:16:24.2065431Z"
    },
    ...
  },
  ...
]
  

Note: Content has been omitted from the JSON response above for brevity.


Was this article helpful?