turbot/kubernetes
steampipe plugin install kubernetes

Table: kubernetes_custom_resource_definition - Query Kubernetes Custom Resource Definitions using SQL

Kubernetes Custom Resource Definitions (CRDs) allow users to create new types of resources that they can later use like the built-in resource types in Kubernetes. These custom resources can be used to store and retrieve structured data. They extend the Kubernetes API, allowing developers to define the kind of resources that they need to work with in their applications.

Table Usage Guide

The kubernetes_custom_resource_definition table provides insights into Custom Resource Definitions within Kubernetes. As a Kubernetes developer or administrator, explore the details of these custom resources through this table, including their structure, configuration, and associated metadata. Utilize it to uncover information about the custom resources, such as their validation schema, versioning details, and the scope of their usage within the Kubernetes cluster.

Examples

Basic Info

Explore the fundamental details of custom resources in your Kubernetes environment to gain insights into their identities and creation times. This can be useful in understanding the composition and history of your resources.

select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition;
select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition;

List CRDs for a particular group

Discover the segments that contain custom resource definitions (CRDs) for a specific group within your Kubernetes environment. This can be particularly useful for managing and tracking your resources, especially in larger deployments.

select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
spec ->> 'group' = 'stable.example.com';
select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
json_extract(spec, '$.group') = 'stable.example.com';

List Certificate type CRDs

Explore which custom resources in your Kubernetes cluster are of the 'Certificate' type. This is useful for managing and tracking security certificates within your system.

select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
status -> 'acceptedNames' ->> 'kind' = 'Certificate';
select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
json_extract(json_extract(status, '$.acceptedNames'), '$.kind') = 'Certificate';

List namespaced CRDs

Explore which custom resource definitions (CRDs) are namespaced in your Kubernetes system. This can be useful for understanding the scope of your CRDs and managing resources more effectively.

select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
spec ->> 'scope' = 'Namespaced';
select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
json_extract(spec, '$.scope') = 'Namespaced';

Get active version detail of each CRD

Explore the active versions of each Custom Resource Definition (CRD) in your Kubernetes environment. This is useful for identifying which versions are currently being served and can help in maintaining version control.

select
name,
namespace,
creation_timestamp,
jsonb_pretty(v) as active_version
from
kubernetes_custom_resource_definition,
jsonb_array_elements(spec -> 'versions') as v
where
v ->> 'served' = 'true';
select
name,
namespace,
creation_timestamp,
v.value as active_version
from
kubernetes_custom_resource_definition,
json_each(spec, '$.versions') as v
where
json_extract(v.value, '$.served') = 'true';

List CRDs created within the last 90 days

Identify the custom resource definitions (CRDs) that have been created in your Kubernetes environment within the last 90 days. This can be useful for tracking recent changes and monitoring the development of your resources.

select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
creation_timestamp >= (now() - interval '90' day)
order by
creation_timestamp;
select
name,
namespace,
uid,
resource_version,
creation_timestamp
from
kubernetes_custom_resource_definition
where
creation_timestamp >= datetime('now', '-90 day')
order by
creation_timestamp;

Get spec detail of each CRD

Discover the segments that detail each Custom Resource Definition (CRD) in your Kubernetes cluster. This query is useful for understanding the scope, versions, and conversion details of your CRDs, which can help you manage and optimize your Kubernetes resources.

select
name,
uid,
creation_timestamp,
spec ->> 'group' as "group",
spec -> 'names' as "names",
spec ->> 'scope' as "scope",
spec -> 'versions' as "versions",
spec -> 'conversion' as "conversion"
from
kubernetes_custom_resource_definition;
select
name,
uid,
creation_timestamp,
json_extract(spec, '$.group') as "group",
json_extract(spec, '$.names') as "names",
json_extract(spec, '$.scope') as "scope",
json_extract(spec, '$.versions') as "versions",
json_extract(spec, '$.conversion') as "conversion"
from
kubernetes_custom_resource_definition;

List manifest resources

Explore which custom resources in your Kubernetes cluster have defined paths. This can be useful in understanding the structure and organization of your resources.

select
name,
namespace,
resource_version,
path
from
kubernetes_custom_resource_definition
where
path is not null;
select
name,
namespace,
resource_version,
path
from
kubernetes_custom_resource_definition
where
path is not null;

Schema for kubernetes_custom_resource_definition

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form.
annotationsjsonbAnnotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.
context_nametextKubectl config context name.
creation_timestamptimestamp with time zoneCreationTimestamp is a timestamp representing the server time when this object was created.
deletion_grace_period_secondsbigintNumber of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set.
deletion_timestamptimestamp with time zoneDeletionTimestamp is RFC 3339 date and time at which this resource will be deleted.
end_linebigintThe path to the manifest file.
finalizersjsonbMust be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed.
generate_nametextGenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided.
generationbigintA sequence number representing a specific generation of the desired state.
labelsjsonbMap of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services.
nametextName of the object. Name must be unique within a namespace.
namespacetextNamespace defines the space within which each name must be unique.
owner_referencesjsonbList of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.
pathtextThe path to the manifest file.
resource_versiontextAn opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed.
source_typetextThe source of the resource. Possible values are: deployed and manifest. If the resource is fetched from the spec file the value will be manifest.
sp_connection_nametextSteampipe connection name.
sp_ctxjsonbSteampipe context in JSON form.
specjsonbSpec describes how the user wants the resources to appear.
start_linebigintThe path to the manifest file.
statusjsonbStatus indicates the actual state of the CustomResourceDefinition.
uidtextUID is the unique in time and space value for this object.

Export

This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.

You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh script:

/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- kubernetes

You can pass the configuration to the command with the --config argument:

steampipe_export_kubernetes --config '<your_config>' kubernetes_custom_resource_definition