CRD
🔍 What is a CRD in Kubernetes?
A CRD (Custom Resource Definition) allows you to extend Kubernetes with your own custom resource types—like MyDatabase, BackupJob, or AppConfig—just like built-in types such as Pod, Service, or Deployment.
❌ Problem
Kubernetes only knows how to manage built-in resources (e.g., Pods, Services, ConfigMaps). But real-world use cases often need custom domain-specific objects, like:
Defining a
KafkaClusterCreating a
PostgreSQLdatabase with parametersRepresenting a
BackuporRestorejob
If you want Kubernetes to manage such non-native resources, you’re out of luck… unless you can teach Kubernetes about them.
✅ Solution: Custom Resource Definition (CRD)
A CRD lets you define a new resource type in Kubernetes.
After defining it, you can use kubectl to create, read, update, and delete your custom resources, just like you do with native resources.
What It Enables:
Kubernetes-native API for your custom objects
GitOps-style config management for app/domain logic
Combine with a controller or Operator for automation
🌍 Real-World Example
🐘 Example: Define a PostgreSQL Cluster as a Custom Resource
CRD YAML (Postgresql CRD definition):
Custom Resource (an instance of Postgresql):
Now you can run:
kubectl apply -f my-postgres.yamlAnd Kubernetes treats it like a native resource!
🧠 Summary
Concept
Description
CRD
Schema definition for a new custom resource (e.g., KafkaCluster)
Custom Resource (CR)
An actual object created from that schema (e.g., my-kafka-cluster)
Why use CRD?
To represent domain-specific objects that Kubernetes doesn’t support natively
Bonus
Combine with a controller/operator to automate behavior (e.g., scaling DB)
🛠 Common Real-Life CRDs You’ll See
CRD
What it Does
Prometheus (via Prometheus Operator)
Defines monitoring targets, rules, alerts
Certificate (via Cert-Manager)
Automatically manages SSL certificates
ArgoCDApplication
Defines GitOps-based app deployments
KafkaCluster
Represents a Kafka cluster in Kubernetes
Backup / Restore
Used by Velero or other backup tools
Le
Last updated