2025-02-25Hünkar Döner

What is Kubernetes CRD? How to Use in EKS?

KubernetesCRDEKSDevelopment
W

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.

  1. CRD: "I define something called MyApp, it will have version and replicas fields."
  2. Custom Resource (CR): The user creates a MyApp YAML file.
  3. Controller: Sees this new MyApp object 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.