DEV Community

丁久
丁久

Posted on • Originally published at dingjiu1989-hue.github.io

Helm Charts: Kubernetes Package Management

This article was originally published on AI Study Room. For the full version with working code examples and related articles, visit the original post.

Helm Charts: Kubernetes Package Management

Helm Charts: Kubernetes Package Management

Helm Charts: Kubernetes Package Management

Helm Charts: Kubernetes Package Management

Helm Charts: Kubernetes Package Management

Introduction

Helm is the de facto package manager for Kubernetes, enabling developers to define, install, and upgrade complex applications through reusable chart packages. A single Helm chart can encapsulate dozens of Kubernetes resources into a versioned, configurable unit that can be deployed across multiple environments with minimal repetition.

This guide covers advanced Helm concepts including chart structure, templating, dependency management, CI/CD integration, and enterprise best practices.

Chart Structure

A well-organized Helm chart follows a standard directory layout:

my-app/

Chart.yaml # Metadata: name, version, dependencies

values.yaml # Default configuration values

values.schema.json # JSON Schema for values validation

charts/ # Sub-charts (managed by helm dependency)

templates/ # Go template YAML files

_helpers.tpl # Named template definitions

deployment.yaml

service.yaml

ingress.yaml

hpa.yaml

tests/ # Test pods for chart validation

test-connection.yaml

crds/ # Custom Resource Definitions

README.md

The Chart.yaml file defines metadata and dependencies:

apiVersion: v2

name: my-app

description: A production-grade web application

version: 1.2.3

appVersion: 2.0.0

kubeVersion: ">=1.25.0-0"

type: application

dependencies:

\\\\- name: postgresql

version: "12.x"

repository: https://charts.bitnami.com/bitnami

condition: postgresql.enabled

\\\\- name: redis

version: "18.x"

repository: https://charts.bitnami.com/bitnami

condition: redis.enabled

Advanced Templating

Helm uses Go templates with the Sprig function library for dynamic resource generation. Beyond simple variable substitution, you can implement complex logic:

{{ /* Conditional resource creation */}}

{{ if .Values.ingress.enabled }}

apiVersion: networking.k8s.io/v1

kind: Ingress

metadata:

name: {{ include "my-app.fullname" . }}

annotations:

{{ toYaml .Values.ingress.annotations | nindent 4 }}

spec:

ingressClassName: {{ .Values.ingress.className }}

rules:

{{ range .Values.ingress.hosts }}

\\\\- host: {{ .host | quote }}

http:

paths:

{{ range .paths }}

\\\\- path: {{ .path }}

pathType: {{ .pathType }}

backend:

service:

name: {{ include "my-app.fullname" $ }}

port:

number: {{ $.Values.service.port }}

{{ end }}

{{ end }}

{{ end }}

Named templates in _helpers.tpl promote reuse:

{{ define "my-app.labels" }}

app.kubernetes.io/name: {{ include "my-app.name" . }}

app.kubernetes.io/instance: {{ .Release.Name }}

app.kubernetes.io/version: {{ .Chart.AppVersion }}

app.kubernetes.io/managed-by: {{ .Release.Service }}

helm.sh/chart: {{ include "my-app.chart" . }}

{{ end }}

{{ define "my-app.probe" }}

initialDelaySeconds: {{ .initialDelay | default 5 }}

periodSeconds: {{ .period | default 10 }}

timeoutSeconds: {{ .timeout | default 3 }}

successThreshold: {{ .successThreshold | default 1 }}

fa


Read the full article on AI Study Room for complete code examples, comparison tables, and related resources.

Found this useful? Check out more developer guides and tool comparisons on AI Study Room.

Top comments (0)