A few days ago, when I tried to install the below application with the latest helm chart using helm v2 command, I got an error message complaining that the helm chart is a helm v3 chart.
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
After struggling for a while, I removed the components that I don’t need and converted the helm v3 chart into a helm v2 chart. However, the installation still failed, when I had another try using the new chart. The CRD resources contained in the helm chart was not created by helm v2 command. This is because helm v2 chart uses a special kind of helm hook named ‘crd-install’ to create the CRD resources as stated below:
https://v2.helm.sh/docs/charts_hooks/
Helm v3 chart uses a different strategy as below. It contains a directory named ‘crds’ to contain the CRD resource definition. Helm v3 command will automatically create the CRD resources under this directory. However, helm v2 command doesn’t recognize this convention or rule.
https://helm.sh/docs/chart_best_practices/custom_resource_definitions/
I tried to modify the CRD resources in the helm chart to use ‘crd-install’ hook, but got the below error message
Error: unable to convert to CRD type: no kind “CustomResourceDefinition” is registered for version “apiextensions.k8s.io/v1” in scheme “k8s.io/client-go/kubernetes/scheme/register.go:65”
After searching it using google, I find the below ticket for helm. This is because helm v2 command doesn’t recognize “apiextensions.k8s.io/v1” schema. It only recognize “apiextensions.k8s.io/v1beta1” schema.
https://github.com/helm/helm/issues/6783
From the below lines of code, we can see that helm v2 command only recognize “apiextensions.k8s.io/v1beta1” schema, while helm v3 command recognize both of “recognize “apiextensions.k8s.io/v1” and “apiextensions.k8s.io/v1beta1”.
helm v2 command: https://github.com/helm/helm/blob/release-2.16/pkg/kube/client.go#L88
helm v3 command: https://github.com/helm/helm/blob/master/pkg/kube/client.go#L73-L79
A good recommendation is to migrate from helm v2 to helm v3. If this is not possible, then you need to create these CRD resources manually using kubectl command. This is usually a one-shot work for a Kubernetes cluster and won’t cause too much work.