๐Ÿ”ง DevOps

Helm

Kubernetes Helm

A Kubernetes package manager. Defines, deploys, and manages applications as charts.

Detailed Explanation

Helm is the package manager for Kubernetes applications. Like apt/yum on Linux and npm for Node.js, Helm bundles complex Kubernetes resources into packages called "Charts," making installation, upgrades, and rollbacks easy. As a CNCF graduated project, it is a core tool in the Kubernetes ecosystem.

Key concepts

  • Chart: A collection of files that define Kubernetes resources
  • Release: An instance of a chart installed in a cluster
  • Repository: A repository for sharing charts
  • Values: Variables that customize chart settings
  • Template: A K8s manifest written as a Go template

Advantages of Helm

  • Reusability: Reuse a chart you have built once across multiple environments
  • Version control: Manage chart versions and release revisions
  • Rollback: Immediately restore the previous version when a problem occurs
  • Dependency management: Define dependencies between charts and install them automatically
  • Community: Thousands of public charts on Artifact Hub

Code Example

Chart.yaml - Chart metadata

# Chart.yaml
apiVersion: v2
name: my-app
description: A Helm chart for My Application
type: application
version: 1.0.0          # ์ฐจํŠธ ๋ฒ„์ „
appVersion: "2.1.0"     # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „

keywords:
  - app
  - web

home: https://github.com/myorg/my-app
sources:
  - https://github.com/myorg/my-app

maintainers:
  - name: Platform Team
    email: platform@myorg.com

dependencies:
  - name: postgresql
    version: "12.x.x"
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled
  - name: redis
    version: "17.x.x"
    repository: https://charts.bitnami.com/bitnami
    condition: redis.enabled

values.yaml - Default settings

# values.yaml
replicaCount: 2

image:
  repository: myorg/my-app
  tag: ""  # Chart.yaml์˜ appVersion ์‚ฌ์šฉ
  pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  create: true
  annotations: {}
  name: ""

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: nginx
  annotations: {}
  hosts:
    - host: my-app.local
      paths:
        - path: /
          pathType: Prefix
  tls: []

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

autoscaling:
  enabled: false
  minReplicas: 2
  maxReplicas: 10
  targetCPUUtilizationPercentage: 80

nodeSelector: {}
tolerations: []
affinity: {}

# ํ™˜๊ฒฝ ๋ณ€์ˆ˜
env:
  LOG_LEVEL: info
  DB_HOST: postgresql

# ์˜์กด์„ฑ ์„ค์ •
postgresql:
  enabled: true
  auth:
    database: myapp
    username: myapp

redis:
  enabled: false

templates/deployment.yaml - Template example

# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "my-app.fullname" . }}
  labels:
    {{- include "my-app.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "my-app.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        {{- include "my-app.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "my-app.serviceAccountName" . }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          env:
            {{- range $key, $value := .Values.env }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 30
          readinessProbe:
            httpGet:
              path: /ready
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}

Helm CLI Commands

# ์ €์žฅ์†Œ ๊ด€๋ฆฌ
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm search repo nginx

# ์ฐจํŠธ ์„ค์น˜
helm install my-release bitnami/nginx
helm install my-app ./my-app-chart -f values-prod.yaml
helm install my-app ./my-app-chart --set replicaCount=3

# ๋ฆด๋ฆฌ์Šค ๊ด€๋ฆฌ
helm list
helm status my-release
helm get values my-release

# ์—…๊ทธ๋ ˆ์ด๋“œ
helm upgrade my-release bitnami/nginx --version 15.0.0
helm upgrade my-app ./my-app-chart -f values-prod.yaml

# ๋กค๋ฐฑ
helm history my-release
helm rollback my-release 2

# ์‚ญ์ œ
helm uninstall my-release

# ๋””๋ฒ„๊น…
helm template my-app ./my-app-chart      # ๋ Œ๋”๋ง๋œ YAML ํ™•์ธ
helm lint ./my-app-chart                  # ์ฐจํŠธ ๊ฒ€์ฆ
helm install my-app ./my-app-chart --dry-run --debug  # ์‹ค์ œ ์„ค์น˜ ์—†์ด ํ…Œ์ŠคํŠธ

Practical Conversation Example

Junior Developer
"Every time we deploy, I have to edit the Deployment, Service, ConfigMap, and Ingress files, and it's exhausting. Managing them per environment is complicated too..."
Senior developer
"Try making it a Helm chart. Define the common resources as templates, and separate only the per-environment differences into values files. You can deploy to production with `helm install -f values-prod.yaml` and to staging with `-f values-staging.yaml`."
Junior Developer
"What do we do if a problem occurs after deployment?"
Senior developer
"Helm stores the release history. With `helm rollback my-app 2`, you can immediately roll back to revision 2. A rollback also finishes within 10 seconds, and a record is kept of which version you rolled back to."

Cautions

Secret Management

Do not store plaintext passwords in values.yaml. Use the helm-secrets plugin or External Secrets Operator.

Release History

Helm stores release information in a Secret (default) or ConfigMap. Limit old revisions with the `--history-max` option.

Pinning Chart Versions

In production, always specify the chart version. Specifying a particular version with `helm upgrade --version 12.3.4` can prevent unexpected changes.

Template Complexity

If Go templates become overly complex, they are hard to maintain. Avoid too many conditionals, and split into multiple charts when necessary.

Learn More