Helm Chart Structure

๐Ÿ”ฅ Vibe Prompt

"Create a Helm chart for a microservice with deployment, service, ingress, configmap, secrets."

helm create myapp
myapp/
โ”œโ”€โ”€ Chart.yaml          # Metadata
โ”œโ”€โ”€ values.yaml         # Default values
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ deployment.yaml
โ”‚   โ”œโ”€โ”€ service.yaml
โ”‚   โ”œโ”€โ”€ ingress.yaml
โ”‚   โ”œโ”€โ”€ configmap.yaml
โ”‚   โ””โ”€โ”€ _helpers.tpl    # Named templates
โ””โ”€โ”€ charts/             # Subchart dependencies

Chart.yaml

apiVersion: v2
name: myapp
version: 1.0.0
appVersion: "1.0"
description: My microservice Helm chart

Deployment Template

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.appName }}
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          envFrom:
            - configMapRef:
                name: {{ .Values.appName }}-config

values.yaml

appName: myapp
replicaCount: 3
image:
  repository: nginx
  tag: stable
service:
  port: 80
ingress:
  enabled: true
  hosts: ["app.example.com"]

Commands

helm lint ./myapp                    # Validate
helm template ./myapp                # Render locally
helm install release-name ./myapp    # Deploy
helm upgrade release-name ./myapp    # Update
helm rollback release-name 1         # Rollback
helm list                           # List releases

Chapter Summary

  • Understand core concepts and principles
  • Master implementation methods and techniques
  • Familiar with common issues and solutions
  • Able to apply in real projects

Further Reading

  • Official documentation and API references
  • Open source examples on GitHub
  • Technical books and online courses
  • Community discussions and tech blogs

Implementation Example

Basic Example

# This section provides a complete implementation example

Steps

  1. Setup: Configure development environment
  2. Data: Prepare required data
  3. Implementation: Build core functionality
  4. Testing: Verify correctness
  5. Optimization: Improve performance

Common Errors

| Error Type | Cause | Solution | |------------|-------|----------| | Compilation | Syntax | Check code syntax | | Runtime | Environment | Verify dependencies installed | | Logic | Algorithm | Step-by-step debugging | | Performance | Efficiency | Use profilers |

Code Example

import sys

def main():
    print("Hello, World!")

if __name__ == "__main__":
    main()

References

  • Official documentation
  • API reference
  • Open source examples
  • Community discussions

Chart.yaml Deep Dive

The Chart.yaml file defines metadata about the chart. It is required for every chart.

Required Fields

| Field | Description | Example | |-------|-------------|--------| | apiVersion | Chart API version (v2 for Helm 3+) | v2 | | name | Chart name | my-app | | version | Chart version (SemVer 2) | 0.1.0 |

Optional but Recommended Fields

| Field | Description | Example | |-------|-------------|--------| | description | One-line description | "A Helm chart for Kubernetes" | | type | application or library | application | | appVersion | Application version being deployed | 1.16.0 | | kubeVersion | Compatible K8s version constraint | >=1.19.0-0 | | keywords | Search keywords | ["nginx", "web", "server"] | | home | Project home URL | https://my-app.example.com | | sources | Source code URLs | [https://github.com/org/my-app] | | maintainers | Maintainer list with name/email/url | [{name: "Alice", email: "a@b.com"}] | | dependencies | List of chart dependencies | [{name: "redis", version: "10.x"}] | | annotations | Extra metadata | {category: "Infrastructure"} |

Example Chart.yaml

apiVersion: v2
name: my-web-app
description: A production-ready web application
type: application
version: 0.1.0
appVersion: "1.0.0"
kubeVersion: ">=1.21.0-0"
keywords:
  - web
  - api
  - nginx
home: https://github.com/myorg/my-web-app
sources:
  - https://github.com/myorg/my-web-app
maintainers:
  - name: DevOps Team
    email: devops@myorg.com
    url: https://myorg.com
dependencies:
  - name: postgresql
    version: 12.x
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

Templates Directory

Every file in templates/ is rendered as a Kubernetes manifest. Helm uses Go templates to inject values.

Standard Template Files

| File | Purpose | |------|---------| | deployment.yaml | Main Deployment resource | | service.yaml | Service resource | | ingress.yaml | Ingress for external access | | configmap.yaml | Configuration data | | secret.yaml | Sensitive data | | serviceaccount.yaml | Service account | | hpa.yaml | Horizontal Pod Autoscaler | | pvc.yaml | Persistent Volume Claim | | _helpers.tpl | Shared template functions |

_helpers.tpl โ€” Reusable Templates

{{- define "myapp.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "myapp.labels" -}}
helm.sh/chart: {{ include "myapp.fullname" . }}
app.kubernetes.io/name: {{ include "myapp.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

Values System

The values.yaml file provides default configuration values that users can override.

Values Priority Order

  1. --set flags (highest priority)
  2. --values custom file
  3. Parent chart values (for subcharts)
  4. Chart's values.yaml (default)

Standard values.yaml Structure

# Global settings
replicaCount: 3

# Image configuration
image:
  repository: nginx
  tag: latest
  pullPolicy: IfNotPresent

# Service configuration
service:
  type: ClusterIP
  port: 80
  targetPort: 8080

# Resource limits
resources:
  requests:
    cpu: 100m
    memory: 128Mi
  limits:
    cpu: 500m
    memory: 512Mi

# Ingress
ingress:
  enabled: false
  className: nginx
  host: my-app.example.com
  tls: []

# Persistence
persistence:
  enabled: true
  size: 8Gi
  storageClass: standard

Built-in Objects

Helm provides several built-in objects accessible in templates.

| Object | Description | Example Value | |--------|-------------|--------------| | .Release.Name | Release name | my-release | | .Release.Namespace | Target namespace | default | | .Release.Service | Service handling the release | Helm | | .Release.IsUpgrade | True if upgrade | true | | .Release.IsInstall | True if install | false | | .Chart.Name | Chart name | my-app | | .Chart.Version | Chart version | 0.1.0 | | .Chart.AppVersion | App version | 1.0.0 | | .Files | Access chart files | .Files.Get "config.json" | | .Capabilities | K8s cluster capabilities | .Capabilities.KubeVersion | | .Template.Name | Current template path | templates/deployment.yaml |

Summary

A Helm chart consists of Chart.yaml, templates/, values.yaml, and supporting files. Understanding this structure is the foundation for creating reusable, configurable Kubernetes packages.

Key takeaways:

  • Chart.yaml defines metadata: name, version, dependencies, maintainers |
  • templates/ contains Go template files that render to Kubernetes manifests |
  • _helpers.tpl stores reusable named templates for labels, names, etc. |
  • values.yaml provides default configuration with clear overridable structure |
  • Built-in objects give access to release, chart, file, and capability info |
  • Charts follow a standard layout for consistency across the ecosystem |

What's Next: Go Templates and Values

The next chapter covers Go template syntax and values management in depth.

Member Exclusive Free Tutorial

This chapter is free exclusive content for registered members! Please login or register to unlock immediately.

Login / Register Now