Dblock247
Dblock247

Reputation: 6725

Helm 3 chart install error: error validating data: apiVersion not set

I have a simple helm chart that will deploy an application to my local copy of kubernetes via docker desktop. If I use kubectl to deploy the yaml one file at a time things work correctly. However, when I try to create a helm chart for easier deployments I get the following error.

helm install demo WebApi

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: apiVersion not set

The error seems to be saying that I am missing an apiVersion map in one or more of my YAML files. However, all of my files have what seems to be the correct apiVersions.

Folder Structure

charts
└── WebApi
    ├── Chart.yaml
    └── templates
        ├── deployment.yaml
        ├── ingress.yaml
        └── services.yaml

Chart.yaml

apiVersion: v2
version: 0.1.0
name: WebApi
appVersion: "1.0"
description: A Helm Chart for WebApi
type: application

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-api
  labels:
    app: demo
    tier: demo-api
spec:
  selector:
    matchLabels:
      app: demo
  replicas: 3
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
        - name: demo
          image: demo/image
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
          resources:
            limits:
              memory: "128Mi" #128 MB
              cpu: "200m" #200 millicpu (.2 cpu or 20% of the cpu)
          livenessProbe:
            httpGet:
              path: /swagger/index.html
              port: 80
            initialDelaySeconds: 15
            timeoutSeconds: 2
            periodSeconds: 5
            failureThreshold: 1
          readinessProbe:
            httpGet:
              path: /swagger/index.html
              port: 80

ingress.yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: demo
spec:
  rules:
    - host: demo.com
      http:
        paths:
          - backend:
              serviceName: demo
              servicePort: 80

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: demo
  labels:
    app: demo
spec:
  type: ClusterIP
  selector:
    app: demo
  ports:
    - name: http
      port: 80
      targetPort: 80

As you can see all of my YAML files have the required apiVersion map however the error still says they are missing. What corrections do I need to make in order for this to work as intended?

Upvotes: 22

Views: 55938

Answers (13)

Abhishek
Abhishek

Reputation: 1160

If you're right about the helm command(s), this is 100% a problem with the helm chart.

Helm is not rendering the first line from your templates(commonly where we define apiVersion)

To debug this issue quickly follow the below steps:

Step-1:

  • Template out your helm chart(use any of the commands)
# with default values, and currently in the chart directory
helm template . | tee debug.yaml

# with values file
helm template . --values=../production.yaml | tee debug.yaml

# only show specific templates file(useful if you're doubtful about a specific file)
helm template .  -s templates/configMap.yaml | tee debug.yaml

NOTE: This command should not generate any error.

Step-2:

  • dry-run this using kubectl
kubectl apply -f debug.yaml --dry-run=client

The command will fail when it reaches the errored resource.

Upvotes: 0

Valentin Kantor
Valentin Kantor

Reputation: 1844

All templates which are not yaml manifests shoud have underscore char at the beginning

Most files in templates/ are treated as if they contain Kubernetes manifests

The NOTES.txt is one exception

But files whose name begins with an underscore (_) are assumed to not have a manifest inside. These files are not rendered to Kubernetes object definitions, but are available everywhere within other chart templates for use.

https://helm.sh/docs/chart_template_guide/named_templates/#partials-and-_-files

Upvotes: 0

poojayg
poojayg

Reputation: 11

Please check the NOTES.txt file under charts->template path. Solution: file name is case sensitive, not suppose to give as Notes.txt, caps is a must because helm will be trying to interpret that file and it tries to generate object for kubernetes.

Upvotes: 0

Mike Rosario
Mike Rosario

Reputation: 7

Test!

$ helm create k8s-helm

$ helm lint k8s-helm/
==> Linting k8s-helm/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

$ kubectl apply -f k8s-helm/ --dry-run=client
error validating "k8s-helm/Chart.yaml": error validating data: kind not set; if you choose to ignore these errors, turn validation off with --validate=false
error validating "k8s-helm/values.yaml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false

Linter did not reveal any errors, but there are problems with validation. How to be?

Helm launch!

$ helm install --debug --dry-run test-app k8s-helm/

Upvotes: 0

mkkot
mkkot

Reputation: 39

I included a library chart. Helm created Chart.lock file that caused the error.

Solution: create .helmignore file in chart's directory with:

Chart.lock

Upvotes: 0

Dhia Balti
Dhia Balti

Reputation: 11

for my case deleting the readme file in the template folder solved the problem .

Upvotes: 1

KDh
KDh

Reputation: 91

In my case, I was adding .json file inside template directory.
I ran helm template -f values.yaml . > deployChart.yaml and found that json file content present in deployChart.yaml.

Moving .json file outside of template directory resolve the issue.

Upvotes: 9

Stephen Blum
Stephen Blum

Reputation: 6834

I had same error message. However my templates were generating broken output.

I fixed this by running first viewing helm template . This generated the output for review. The problem was ---apiVersion: v2 was at the top of the generated chart. The triple hyphens --- are not intended.

To fix, changing {{- end -}} to {{ end }} at the bottom of my generated charts files. This allows for line breaks on multi-chart generated templates.

Helm Chart Template Fix

Upvotes: 6

Nidhin
Nidhin

Reputation: 636

I came across the same issue. I was missing a from apiVersion in one of the yml files added to templates folder. A typo but worth checking.

Upvotes: 0

YK1
YK1

Reputation: 7612

I came across this error while using Azure DevSpaces (which in turn uses helm for workload deployment). It turned out some of my template files had UTF-8 BOM and helm (in DevSpaces) was not able to handle it, although locally installed helm client was able to resolve the templates fine. I removed the BOM and that resolved the issue in DevSpaces.

Upvotes: 2

ERai
ERai

Reputation: 143

I run helm install anyname1 . --dry-run --debug and got incomprehensible error messages. then I run helm template -f values.yaml . > deployChart.yaml and I saw some strange characters in the generated file.

My error: I created an additional file 'cronJob.yaml' inside templates using VS (visual studio) and added my content... I presume helm is not compatible -somehow- with the OS-windows encoding... anyways I hope this helps.

My solution: I copied an existing file, then renamed it and then I pasted my content.

Upvotes: 13

tom
tom

Reputation: 864

I had a similar problem with the same error message, but not exactly the same problem. The problem for me seems to have been a comment at the start of one of the helm templates. It seems helm did not handle this case well. When i moved the comment down a bit it worked.

Upvotes: 59

kool
kool

Reputation: 3613

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: apiVersion not set

This error means that the installation command was executed from wrong directory or wrong path to chart has been provided.

In order to install it, you have to either execute from the directory where Chart.yaml is placed or provide the path to this directory as an argument in helm install command, example from WebApi directory:

helm install webapi .

Upvotes: -5

Related Questions