How to list applied Custom Resource Definitions in kubernetes with kubectl
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Kubernetes, Custom Resource Definitions (CRDs) extend the Kubernetes API to allow for the creation of bespoke resources. Organizations and developers use CRDs to tailor Kubernetes functionalities to specific use-case requirements. Managing and listing these Custom Resource Definitions is crucial for maintaining cluster health and ensuring that applications and services behave as expected.
This article explores the methods to list applied CRDs using the kubectl command line tool, providing technical explanations, examples, and a concise summary table.
Understanding Custom Resource Definitions
Custom Resource Definitions allow users to create their own resources just like Pods, Services, and Deployments. This offers a way to define APIs tailored to specific use cases. Here’s a snapshot of how CRDs function:
- Resource specification: CRDs are defined in YAML files, much like other Kubernetes objects.
- Versioning: CRDs support versioning, enabling gradual transitions across scheme changes.
- Schema validation: Employs OpenAPI Schema to enforce valid configurations.
- Namespaced vs. Cluster-scoped: CRDs can be either namespaced or cluster-scoped.
Listing CRDs with kubectl
Using kubectl, CRDs can be listed and examined in various ways. Below are the different ways to achieve this task, along with technical details and examples.
Basic Listing
To retrieve a list of all applied Custom Resource Definitions, use:
This command will return a list of CRD names along with their established age.
Detailed Listing
For a more detailed information output, the -o wide flag can be employed:
Here’s an example of typical output:
Each row includes names of CRDs and the time they were created.
Specific Details with YAML/JSON
To fetch complete details of a specific CRD in YAML or JSON format, use:
or
Output for YAML provides extensively detailed insights, including apiVersion, kind, metadata, and specifications. This is useful for debugging or reviewing CRD configurations.
Filtering with Custom Columns
You can extract specific details using custom columns:
This command gives a clear view of each CRD and its respective version.
Using Label Selectors
CRDs might carry labels assigned during creation, useful for filtered searches. For instance:
This query retrieves CRDs associated with the label app=custom-app.
Applying CRDs
Applying a new CRD involves submitting the YAML definition to the cluster. Here’s an outline:
- Write the CRD YAML: Define the resource's attributes, name, spec, etc.
- Apply the CRD:
- Verify the CRD:
After application, the CRD becomes available like any other Kubernetes resource.
Summary Table of Commands
| Task | Command |
| List all CRDs | kubectl get crds |
| List CRDs with details | kubectl get crds -o wide |
| Fetch specific CRD details | kubectl get crd <crd-name> -o yaml
kubectl get crd <crd-name> -o json |
| Extract using columns | kubectl get crds -o custom-columns=NAME:.metadata.name,VERSION:.spec.version |
| Filter with labels | kubectl get crds -l <label> |
| Apply a new CRD | kubectl apply -f <yaml-file> |
| Verify new CRD | kubectl get crd <crd-name> |
Conclusion
Custom Resource Definitions expand Kubernetes capabilities, enabling more complex and specialized workloads to run efficiently. Understanding how to list and manage CRDs with kubectl ensures that administrators and developers can effectively leverage these powerful tools. From simple queries to detailed inspections and labels, knowing how to navigate the CRD landscape is a foundational skill for anyone working within Kubernetes environments.

