Working with Custom Resources
Once a CRD is registered in your cluster, you can create and manage custom resources (CRs) using the same kubectl commands you use for built-in resources like Pods and Deployments.
Creating a Custom Resource
Given a CRD for CronTab in the stable.example.com group:
apiVersion: stable.example.com/v1
kind: CronTab
metadata:
name: my-cron-job
namespace: default
spec:
cronSpec: "*/5 * * * *"
image: my-cron-image:latest
replicas: 3
# Apply the custom resource
kubectl apply -f my-crontab.yaml
Listing CRDs in the Cluster
# See all registered CRDs
kubectl get crd
# Output:
# NAME CREATED AT
# crontabs.stable.example.com 2025-01-15T10:30:00Z
# certificates.cert-manager.io 2025-01-10T08:00:00Z
# Get details about a specific CRD
kubectl describe crd crontabs.stable.example.com
Querying Custom Resources
Once created, custom resources work just like any other resource type:
# List all CronTab resources
kubectl get crontabs
kubectl get ct # using the short name
# Output with additionalPrinterColumns:
# NAME SCHEDULE REPLICAS AGE
# my-cron-job */5 * * * * 3 2m
# Get detailed YAML output
kubectl get ct my-cron-job -o yaml
# Describe a custom resource
kubectl describe ct my-cron-job
# Get custom resources across all namespaces
kubectl get ct -A
Editing and Deleting
# Edit a custom resource
kubectl edit ct my-cron-job
# Patch a field
kubectl patch ct my-cron-job \
--type=merge \
-p '{"spec":{"replicas":5}}'
# Delete a custom resource
kubectl delete ct my-cron-job
Key Takeaways
- Custom resources use the same kubectl verbs as built-in resources:
get,describe,edit,delete - Short names defined in the CRD work everywhere
kubectl get crdlists all registered custom resource types in the cluster- Custom resources are validated against the schema defined in their CRD