Skip to main content

Creating Chart Structure

1. Generating New Chart

Example: Using Helm CLI to create a new chart

helm create my-app
Command Description Notes
helm create <chart-name> Creates a new chart directory structure Generates standard Helm chart layout with templates, values, and metadata
Note: The created chart includes a Chart.yaml file, values.yaml, and a templates/ directory.

2. Understanding Chart Directory Layout

Directory/File Description Notes
charts/ Sub-charts directory Used for embedding dependent charts
templates/ Template files directory Contains Kubernetes manifests with Go template syntax
values.yaml Default values file Defines default configuration values for templates
Chart.yaml Chart metadata file Contains chart name, version, appVersion, etc.
README.md Chart documentation Optional but recommended for chart usage instructions
values.schema.json Schema for values validation NEW in Helm 3.10+
.helmignore Ignore patterns for chart packaging Similar to .gitignore but for Helm chart packaging

Example: Chart.yaml structure

apiVersion: v2
name: my-app
description: A Helm chart for my application
type: application
version: 0.1.0
appVersion: "1.16.0"
Note: The templates/ directory is where all Kubernetes manifest files (Deployment, Service, ConfigMap, etc.) are stored and rendered using Go templates.

3. Creating Chart.yaml Metadata

Field Description Example
apiVersion API version of the chart format v2
name Name of the chart my-app
version Chart version (semver 2.0) 1.0.0
appVersion Version of the application being deployed 1.2.3
description Short description of the chart A Helm chart for deploying my-app
home Home page URL of the project https://example.com/my-app
sources URLs to source code of the project [https://github.com/example/my-app]
maintainers List of maintainers with name and email
- name: John Doe
  email: john@example.com
icon URL to an icon image https://example.com/icon.png
keywords List of keywords for the chart [app, helm, kubernetes]
annotations Annotations to add to the chart helm.sh/chart: my-app-1.0.0

Example: Chart.yaml

apiVersion: v2
name: my-app
version: 1.0.0
appVersion: "1.2.3"
description: A Helm chart for deploying my-app
home: https://example.com/my-app
sources:
  - https://github.com/example/my-app
maintainers:
  - name: John Doe
    email: john@example.com
icon: https://example.com/icon.png
keywords:
  - app
  - helm
  - kubernetes
annotations:
  helm.sh/chart: my-app-1.0.0

4. Defining Chart Type

Chart Type Description Use Case
application Standard chart for deploying applications to Kubernetes Deploying microservices, web apps, or backend services
library Chart that defines Kubernetes manifests for reuse in other charts Reusable components like common ConfigMaps or RBAC rules
operator Chart that deploys an operator to manage custom resources Managing stateful applications or CRDs with custom controllers

Example: Chart.yaml for Application Type

apiVersion: v2
name: my-app
description: A Helm chart for deploying a sample application
type: application
version: 1.0.0
appVersion: "1.0"

5. Creating values.yaml File

Property Default Value Description
replicaCount 1 Number of replicas for the deployment
image.repository nginx Container image repository name
image.tag latest Container image tag
service.type ClusterIP Kubernetes service type to expose the application
service.port 80 Port to expose the service on

Example: Default values.yaml

replicaCount: 1

image:
  repository: nginx
  tag: latest

service:
  type: ClusterIP
  port: 80

6. Creating .helmignore File

The .helmignore file is used to specify files and directories that should be excluded from the Helm chart archive when packaging the chart. This is useful for excluding temporary files, IDE configuration, or any other content that should not be included in the chart distribution.

File Pattern Description Example
*.tmp Excludes all temporary files *.tmp
node_modules/ Excludes the node_modules directory node_modules/
.git/ Excludes the .git directory .git/
README.md Excludes the README.md file README.md

Example: .helmignore content

*.tmp
.DS_Store
.git/
node_modules/
*.log

7. Organizing Template Files

Template files in Helm charts are organized under the templates/ directory. This section outlines how to structure and manage these files effectively.

File Type Description Usage
Deployment.yaml Defines a Kubernetes Deployment resource Used to deploy applications with desired state
Service.yaml Defines a Kubernetes Service resource Exposes application pods to network traffic
ConfigMap.yaml Defines a Kubernetes ConfigMap resource Stores non-confidential configuration data
Secret.yaml Defines a Kubernetes Secret resource Stores confidential information like passwords

Example: Deployment Template

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "myapp.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "myapp.labels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "myapp.labels" . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          ports:
            - containerPort: {{ .Values.service.port }}

Example: Service Template

apiVersion: v1
kind: Service
metadata:
  name: {{ include "myapp.fullname" . }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "myapp.labels" . | nindent 4 }}
Note: Template files use Go template syntax. Helm provides built-in functions and variables to help construct templates dynamically.

8. Creating NOTES.txt File

Example: Basic NOTES.txt Content

Get started by running:
  helm install my-release ./my-chart

You can also run:
  helm status my-release
Field Description Usage
NOTES.txt File for post-installation instructions Displayed after chart installation
Template Variables Available in templates Use {{ .Release.Name }} to reference release name
Note: NOTES.txt is processed as a Go template, allowing dynamic content based on chart values.
Warning: Avoid including sensitive information in NOTES.txt as it's displayed publicly after installation.

9. Setting Up charts/ Subdirectory

The charts/ subdirectory in a Helm chart is used to store dependencies on other charts. This directory is automatically created when you initialize a new chart using the helm create command.

Directory Description Usage
charts/ Stores sub-charts (dependencies) Used for organizing chart dependencies

Example: Adding a dependency

dependencies:
- name: nginx
  version: 1.2.3
  repository: https://charts.example.com
Note: The charts/ directory is managed by Helm's dependency management system. When you run helm dependency update, Helm will download and place the dependencies into this directory.

10. Creating crds/ Directory

The crds/ directory in a Helm chart is used to define Custom Resource Definitions (CRDs) that the chart depends on or creates. This directory is particularly useful when your chart needs to install CRDs as part of its deployment.

File Description Notes
crds/my-crd.yaml Custom Resource Definition file Defines the schema for a custom resource type

Example: Defining a CRD in Helm Chart

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: mycrds.example.com
spec:
  group: example.com
  versions:
    - name: v1
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                replicas:
                  type: integer
                  minimum: 1
Note: CRDs defined in the crds/ directory are installed before the chart's resources, ensuring that the custom resource types are available when the chart is deployed.

11. Creating templates/_helpers.tpl

Example: Basic helpers template

{{- define &#34;myapp.name&#34; -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix &#34;-&#34; -}}
{{- end -}}

{{- define &#34;myapp.fullname&#34; -}}
{{- $name := include &#34;myapp.name&#34; . -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix &#34;-&#34; -}}
{{- else -}}
{{- printf &#34;%s-%s&#34; .Release.Name $name | trunc 63 | trimSuffix &#34;-&#34; -}}
{{- end -}}
{{- end -}}
Helper Description Usage
myapp.name Generates a consistent name for the application {{ include "myapp.name" . }}
myapp.fullname Creates a full name combining release and app name {{ include "myapp.fullname" . }}
Note: The _helpers.tpl file is used to define templates that can be reused across other templates in your chart.

Was this article helpful?