Custom Resource Definitions (CRDs) in Helm

Saurabh AdhauSaurabh Adhau
3 min read

Introduction

Custom Resource Definitions (CRDs) are a powerful feature of Kubernetes that extends its API to allow users to define their custom resources and controllers. When combined with Helm, a package manager for Kubernetes, CRDs enable users to streamline the deployment and management of custom resources alongside their applications. In this article, we'll explore CRDs in Helm, provide an example to illustrate their usage and discuss their benefits in Kubernetes environments.

Understanding CRDs in Helm

CRDs in Helm enable users to define and manage custom resources within Helm charts, allowing for greater flexibility and customization in Kubernetes deployments. CRDs are typically included in Helm charts alongside other Kubernetes resources, and Helm facilitates the deployment and management of these custom resources alongside the main application components.

Example: Deploying a Custom Resource with Helm

Let's consider an example where we want to deploy a custom resource named MyCustomResource using Helm:

  1. Define the Custom Resource Definition (CRD)

    First, we define the CRD for MyCustomResource in a YAML file, mycustomresource-crd.yaml:

     apiVersion: apiextensions.k8s.io/v1
     kind: CustomResourceDefinition
     metadata:
       name: mycustomresources.example.com
     spec:
       group: example.com
       names:
         kind: MyCustomResource
         plural: mycustomresources
         singular: mycustomresource
       scope: Namespaced
       versions:
         - name: v1
           served: true
           storage: true
    

    This CRD definition specifies the group, kind, and version of the custom resource, along with its scope (Namespaced or Cluster).

  2. Create the Helm Chart

    Next, we create a Helm chart named my-custom-resource:

     helm create my-custom-resource
    
  3. Include the CRD in the Helm Chart

    We include the CRD YAML file (mycustomresource-crd.yaml) in the templates directory of the Helm chart.

  4. Deploy the Helm Chart

    Finally, we deploy the Helm chart to Kubernetes:

     helm install my-custom-resource ./my-custom-resource
    

Benefits of CRDs in Helm

  1. Customization: CRDs enable users to define custom resources tailored to their specific application requirements, allowing for greater customization and flexibility in Kubernetes deployments.

  2. Abstraction: By abstracting custom resources into Helm charts, users can easily manage and deploy complex applications consisting of both standard Kubernetes resources and custom resources.

  3. Reusability: Helm charts containing CRDs can be shared and reused across different projects, promoting consistency and standardization in Kubernetes deployments.

  4. Automation: Helm simplifies the deployment and management of CRDs alongside other Kubernetes resources, enabling the automation of complex application workflows.

Conclusion

Custom Resource Definitions (CRDs) in Helm offer a powerful mechanism for extending Kubernetes with custom resources tailored to specific application needs. By combining Helm's package management capabilities with CRDs, users can streamline the deployment and management of custom resources alongside their applications, leading to greater customization, reusability, and automation in Kubernetes environments. Whether deploying simple microservices or complex distributed systems, CRDs in Helm empower users to leverage the full potential of Kubernetes for their unique use cases.

10
Subscribe to my newsletter

Read articles from Saurabh Adhau directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Saurabh Adhau
Saurabh Adhau

As a DevOps Engineer, I thrive in the cloud and command a vast arsenal of tools and technologies: โ˜๏ธ AWS and Azure Cloud: Where the sky is the limit, I ensure applications soar. ๐Ÿ”จ DevOps Toolbelt: Git, GitHub, GitLab โ€“ I master them all for smooth development workflows. ๐Ÿงฑ Infrastructure as Code: Terraform and Ansible sculpt infrastructure like a masterpiece. ๐Ÿณ Containerization: With Docker, I package applications for effortless deployment. ๐Ÿš€ Orchestration: Kubernetes conducts my application symphonies. ๐ŸŒ Web Servers: Nginx and Apache, my trusted gatekeepers of the web.