Helm 패키지 관리

Kubernetes 애플리케이션의 패키징, 배포, 버전 관리


Kubernetes 애플리케이션의 패키징, 배포, 버전 관리

목표: 복잡한 애플리케이션을 템플릿화하여 효율적으로 관리할 수 있는 수준


📦 Helm 개요

개념

Kubernetes용 패키지 매니저.

graph TB
    subgraph "Helm 아키텍처"
        CLI["💻 Helm CLI"] -->|"gRPC"| TILLER["🎛️ Helm (Tiller)"]
        TILLER -->|"API"| K8S["🔷 Kubernetes API"]
        
        CHART["📋 Chart"] -->|"템플릿"| TILLER
        VALUES["⚙️ values.yaml"] -->|"설정"| TILLER
    end

핵심 개념:

  • Chart: 패키지 (템플릿 + 설정)
  • Release: 설치된 인스턴스
  • Repository: Chart 저장소

🛠️ 설치

# Helm 설치
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

# 버전 확인
helm version

# 저장소 추가
helm repo add stable https://charts.helm.sh/stable
helm repo add bitnami https://charts.bitnami.com/bitnami

# 저장소 업데이트
helm repo update

📋 Chart 구조

mychart/
├── Chart.yaml          # Chart 메타데이터
├── values.yaml         # 기본 설정값
├── charts/             # 의존성 Chart
├── templates/          # Kubernetes 템플릿
│   ├── _helpers.tpl    # 헬퍼 템플릿
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── ingress.yaml
│   └── ...
└── README.md

Chart.yaml

apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
type: application
version: 1.0.0
appVersion: "1.16.0"
dependencies:
- name: mysql
  version: "9.x.x"
  repository: "https://charts.bitnami.com/bitnami"
  condition: mysql.enabled

values.yaml

# 기본 설정값
replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent
  tag: ""

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: ""
  annotations: {}
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific

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

📝 템플릿 작성

기본 문법

# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mychart.fullname" . }}
  labels:
    {{- include "mychart.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "mychart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "mychart.selectorLabels" . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          resources:
            {{- toYaml .Values.resources | nindent 12 }}

조건문

# Ingress 활성화 여부
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "mychart.fullname" . }}
spec:
  rules:
  {{- range .Values.ingress.hosts }}
  - host: {{ .host | quote }}
    http:
      paths:
      {{- range .paths }}
      - path: {{ .path }}
        pathType: {{ .pathType }}
        backend:
          service:
            name: {{ include "mychart.fullname" $ }}
            port:
              number: {{ $.Values.service.port }}
      {{- end }}
  {{- end }}
{{- end }}

반복문

# 환경변수
env:
{{- range $key, $value := .Values.env }}
  - name: {{ $key }}
    value: {{ $value | quote }}
{{- end }}

🚀 Chart 사용

설치

# 저장소에서 설치
helm install my-release bitnami/nginx

# 로컬 Chart 설치
helm install my-release ./mychart

# 설정값 오버라이드
helm install my-release ./mychart \
  --set replicaCount=3 \
  --set image.tag=latest

# values 파일 사용
helm install my-release ./mychart -f custom-values.yaml

업그레이드

# 업그레이드
helm upgrade my-release ./mychart

# 강제 재설치
helm upgrade --install my-release ./mychart

# 롤백
helm rollback my-release 1

관리

# 릴리즈 목록
helm list

# 릴리즈 상태
helm status my-release

# 릴리즈 히스토리
helm history my-release

# 릴리즈 삭제
helm uninstall my-release

# 템플릿 렌더링 (미리보기)
helm template my-release ./mychart

📦 Chart 저장소

Chart Museum

# Chart Museum 설치
helm install chartmuseum stable/chartmuseum

# Chart 패키징
helm package ./mychart

# 저장소에 업로드
curl --data-binary "@mychart-1.0.0.tgz" http://chartmuseum.example.com/api/charts

# 저장소 추가
helm repo add myrepo http://chartmuseum.example.com

OCI 레지스트리 (Helm 3.8+)

# OCI 레지스트리 로그인
helm registry login registry.example.com

# Chart 푸시
helm push mychart-1.0.0.tgz oci://registry.example.com/charts

# Chart 풀
helm pull oci://registry.example.com/charts/mychart --version 1.0.0

📋 체크리스트

  • Chart 구조 이해
  • values.yaml 작성
  • 템플릿 문법 (변수, 조건문, 반복문)
  • Helm 설치/업그레이드/롤백
  • Chart 저장소 관리
  • 의존성 관리
  • OCI 레지스트리 사용

🔗 관련 노트

  • 03-04-Kustomize-설정-관리 — 설정 관리 대안
  • 03-09-GitOps-ArgoCD — GitOps 배포
  • 01-04-Deployment-관리 — 워크로드 배포

마지막 업데이트: 2026-06-01