Kubernetes Concepts: Operators and CRDs
1. Custom Resource Definitions (CRDs)
- What are CRDs?Custom Resource Definitions (CRDs) extend Kubernetes by allowing users to define their own custom resources.
- Why use CRDs?They enable the management of application-specific resources within Kubernetes, just like native resources (Pods, Services, Deployments).
- Example Use Case:
- Defining a
Database
CRD to manage database instances via Kubernetes API.
- Defining a
2. Kubernetes Operators
- What is a Kubernetes Operator?
- An Operator is a controller that automates application management using CRDs.
- It continuously watches for changes and ensures the desired state of the application.
- Why use Operators?
- Automate complex deployments (e.g., databases, monitoring stacks).
- Handle upgrades, backups, and failure recovery.
- Example Use Case:
- APostgreSQL Operator to manage database instances in Kubernetes.
3. Key Differences Between CRDs and Operators
Feature | CRD | Operator |
---|---|---|
Purpose | Extends Kubernetes API | Automates application lifecycle |
Complexity | Defines custom resources | Uses CRDs + controllers to manage resources |
Use Case | Define resource structures | Automate complex operations (e.g., upgrades, backups) |
4. Popular Kubernetes Operators
- Prometheus Operator – Deploy and manage Prometheus monitoring stack.
- Elasticsearch Operator – Manage Elasticsearch clusters.
- Kafka Operator – Handle Kafka brokers in Kubernetes.
To implement aCustom Resource Definition (CRD) in your Kubernetes cluster, follow these steps:
1. Create the CRD Definition
Save the following YAML asmycrd.yaml
:
apiVersion:apiextensions.k8s.io/v1kind:CustomResourceDefinitionmetadata:name:widgets.example.comspec:group:example.comnames:kind:Widgetplural:widgetsscope:Namespacedversions:-name:v1served:truestorage:trueschema:openAPIV3Schema:type:objectproperties:spec:type:objectproperties:size:type:stringcolor:type:string
Apply it using:
kubectl apply-f mycrd.yaml
2. Define a Custom Resource (CR)
After creating the CRD, define an instance of the custom resource. Save this aswidget.yaml
:
apiVersion:example.com/v1kind:Widgetmetadata:name:my-widgetspec:size:"large"color:"blue"
Apply it:
kubectl apply-f widget.yaml
3. Verify the Custom Resource
Check if the CRD is created:
kubectl get crds
Check the created custom resource:
kubectl get widgets
Describe the resource:
kubectl describe widget my-widget
4. Clean Up
To remove the CRD:
kubectl delete crd widgets.example.com
Next Steps
- Implement acustom controller to manage
Widget
resources. - Extend the CRD with validation rules.
- Integrate with Kubernetes Operators for automation.
Happy Learning !!!
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse