What is Kubernetes CRD? How to Use in EKS?
What is Kubernetes CRD? How to Use in EKS?
The strongest aspect of Kubernetes is its extensibility. By default, it knows resources like Pod, Service, Deployment. But what if you want to teach Kubernetes new objects specific to your business? For example, a Database or Website object?
This is where Custom Resource Definition (CRD) allows you to add new types to the Kubernetes API. Many add-ons on Amazon EKS (ArgoCD Application, Prometheus ServiceMonitor) are actually CRDs.
CRD and Controller Logic (Operator Pattern)
Creating a CRD is not enough (it's like saving data to a database). You need to write a Controller (brain) to do work based on that data.
- CRD: "I define something called
MyApp, it will haveversionandreplicasfields." - Custom Resource (CR): The user creates a
MyAppYAML file. - Controller: Sees this new
MyAppobject and creates the necessary Deployments and Services in the background.
CRD Example in EKS
A simple CRD definition:
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:
cronSpec:
type: string
image:
type: string
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
When you apply this file, your EKS cluster now recognizes an object called CronTab.
CRDs transform Kubernetes from just a container manager into a platform that can manage everything.