Deploying Helm Charts: The Importance of Installing CRDs First

Kadir Islow | May 31, 2023 min read

The Importance of Installing CRDs First

If you’ve been working with Helm, the popular package manager for Kubernetes, you may have encountered an error message that goes something like this: “Helm install fails…ensure CRDs are installed first.” This frustrating error is a common occurrence for many developers and operators who are trying to deploy applications using Helm.

In this blog post, we’ll delve into the reasons behind this error and explore why it’s essential to install Custom Resource Definitions (CRDs) before deploying other resources with Helm.

Understanding CRDs and Helm

CRD

Before we dive into the issue at hand, let’s quickly review the basics. Custom Resource Definitions (CRDs) are a Kubernetes feature that allows you to extend the Kubernetes API with your own custom resources. These custom resources enable you to define and manage applications or services specific to your needs. CRDs play a crucial role in extending Kubernetes capabilities beyond its built-in resource types.

Helm

Helm, on the other hand, is a powerful tool for managing Kubernetes applications and resources using charts. A Helm chart is a collection of files that describe a set of Kubernetes resources, including deployment configurations, services, and ingress rules, among others. Helm simplifies the deployment process by providing a templating mechanism and a way to manage releases and upgrades in a consistent manner.

The Challenge: Installing CRDs First

When deploying applications using Helm, it’s crucial to understand the order in which resources should be installed. Helm expects that CRDs, being custom resources, are installed before other resources that may depend on them. However, this order is not always enforced by default, and failing to install CRDs first can lead to errors and unexpected behavior.

Here are a few reasons why CRDs should be installed before other resources:

Dependency Resolution: Certain Kubernetes resources, such as CustomResourceDefinitions, may be referenced by other resources. By installing CRDs first, you ensure that these dependencies are satisfied before attempting to deploy resources that rely on them. Helm relies on this proper order to prevent conflicts and inconsistencies during the deployment process.

Validation and Schema Enforcement: CRDs define the structure and behavior of custom resources. By installing CRDs before deploying other resources, you allow Kubernetes to validate and enforce the schema defined in the CRDs. This ensures that the resources being deployed conform to the expected structure, reducing the chances of deployment failures or runtime issues.

Avoiding Resource Conflicts: Installing CRDs before other resources helps prevent conflicts that may arise when resources with the same name are installed. Since CRDs often define custom resource names, installing them first ensures that other resources don’t unintentionally use the same name, leading to conflicts that can cause deployment failures.

Resolving my Issue

During my recent attempt to deploy an operator on Google Kubernetes Engine (GKE), I encountered a common issue with Helm installation failures. This roadblock led me to develop a convenient solution, a simple script that eliminates the need for manual extraction of YAML files.

Getting Stareted

To begin with, clone the repository:

$ git clone https://github.com/kislow/helm-crd-extractor

Rendering the Helm Chart

After successfully cloning the repository, proceed to render your Helm chart by executing the following command:

$ Helm template . > rendered_file.yaml

Extracting the Rendered File

Now, it’s time to extract the rendered file. This process is pretty straightforward. Just follow the steps below:

  1. Make sure to read the prerequisites before running the script.
  2. Locate the rendered file “rendered_file.yaml” you obtained from the previous step.
  3. Open your terminal or command prompt and navigate to the directory where you cloned the repository.
  4. Execute the script by running the following command:
$ python3 main.py --file rendered_file.yaml --path .

Applying manifest

# crds first
$ kubectl apply -f crdsOnly.yaml
# non crd's after
$ kubectl apply -f noCrds.yaml

Conlusion

By using this script, I no longer need to face the hassle of manual YAML file extraction.