Kubernetes is incredibly powerful — it manages containers, networking, and scaling with ease. But what makes it truly flexible is its ability to go beyond built-in objects like Pods, Services, and Deployments.
That’s where Custom Resources (CRs) come in.
In this post, we’ll break down what custom resources are, why they exist, and how you can create one to extend Kubernetes just like a pro.
🔍 What Are Custom Resources?
In simple terms, a Custom Resource (CR) is a user-defined API object that extends the Kubernetes API.
By default, Kubernetes comes with built-in resource types like:
- pods
- deployments
- services
- configmaps
But what if you want Kubernetes to understand your own type of resource — say, Database, Cache, or CronJobTemplate?
That’s exactly what a Custom Resource Definition (CRD) allows you to do.
đź§± CustomResourceDefinition (CRD)
A CRD is a YAML definition that tells Kubernetes about your new resource type — its name, structure, and how it should behave.
Once a CRD is created, you can use kubectl commands to create, read, update, and delete your new resource — just like any built-in one.
Example CRD:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
schedule:
type: string
image:
type: string
replicas:
type: integer
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
Once you apply this CRD:
kubectl apply -f crd-crontab.yaml
Kubernetes now understands a new object type called CronTab.
🚀 Creating a Custom Resource
After defining your CRD, you can create actual instances of that resource.
Here’s an example of a Custom Resource (CR):
apiVersion: stable.example.com/v1
kind: CronTab
metadata:
name: my-cron
spec:
schedule: "*/5 * * * *"
image: my-cron-image
replicas: 2
Apply it using:
kubectl apply -f my-cron.yaml
Now, try:
kubectl get crontabs
You’ll see:
NAME AGE
my-cron 10s
Just like you would for pods or services — except this is your custom resource!
⚙️ How Custom Resources Work Behind the Scenes
When you create a CRD:
- Kubernetes API server dynamically adds new REST endpoints (like /apis/stable.example.com/v1/crontabs).
- The Kubernetes control plane starts accepting your new object type.
- You can manage these objects just like native Kubernetes ones.
However, a CRD alone doesn’t perform any action.
If you want automation (like creating pods or databases when a CR is created), you need a **Controller or Operator **that watches your CRs and acts accordingly.
🤖 Custom Resources and Operators
Operators are like “smart agents” that extend Kubernetes behavior using CRDs.
For example:
- Prometheus Operator → adds CRDs like ServiceMonitor, Alertmanager.
- Cert-Manager → adds CRDs like Certificate and Issuer.
- ArgoCD → uses CRDs like Application to manage GitOps workflows.
These operators continuously monitor custom resources and automatically take actions — just like Kubernetes manages pods.
đź§ Why Use Custom Resources?
- Extensibility: Add new resource types without changing Kubernetes core code.
- Automation :Combine with controllers to automate complex tasks.
- Declarative Management: Use YAML manifests to define custom workflows.
- Integration: Ideal for building Operators, CI/CD systems, or internal DevOps tools.
đź§ Conclusion
Custom Resources turn Kubernetes from just a container orchestrator into a powerful platform for automation.
They’re the foundation for Operators, GitOps, and advanced DevOps workflows.
If you understand how CRDs and CRs work, you can extend Kubernetes to manage almost anything — not just containers.
🚀 Quick Recap
- CRD (CustomResourceDefinition): Defines your new resource type.
- CR (Custom Resource): An instance of that type.
- Controller/Operator: Automates behavior based on your CRs.
Top comments (0)