C.W.K.
Stream
Lesson 05 of 08 · published

Helm — Kubernetes 용 templated YAML

~12 min · yaml, helm, kubernetes, templating

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

위에 Go template 깐 YAML

Helm 이 Kubernetes 의 패키지 매니저. chart 가 YAML template 디렉토리. helm install 이 template 을 values.yaml 로 렌더하고 결과 적용. 바닥엔 같은 K8s manifest; 중간 templating layer 가 한 chart 로 dev/staging/prod 에 다른 값으로 배포.

Chart 레이아웃

  • Chart.yaml — chart 메타데이터.
  • values.yaml — 기본 값 (chart 의 API).
  • templates/{{ .Values.x }} 치환된 YAML template.
  • charts/ — sub-chart.

String quoting 함정

Helm template 이 텍스트 출력. 결과가 그 후 YAML 로 파싱. 그래서 bare 값 emit 한 template 이 YAML 에 의해 다시 타이핑됨 — port: 8000 인 {{ .Values.port }} 가 K8s 가 string 기대하는 곳에서도 정수 8000 됨. 렌더된 출력 명시적 quote: {{ .Values.port | quote }} 또는 quote 로 wrap.

'렌더된 YAML 이 가끔 무효 YAML' 문제: Helm template 이 깨진 YAML (누락된 newline, 이중 파이프, 잘못 들여쓴 block) 만들 수 있어. CI 에서 helm template ./chart 실행 후 kubeconform 또는 yq . 로 파이프 — render-time 검증, 배포-time 만 아님.

Code

Chart 레이아웃·text
pippa-chart/
├── Chart.yaml
├── values.yaml
└── templates/
    ├── deployment.yaml
    ├── service.yaml
    ├── configmap.yaml
    └── _helpers.tpl
values.yaml + template·yaml
# values.yaml
image:
  repository: ghcr.io/cwk/pippa
  tag: '1.0'
replicas: 3
port: 8000
logLevel: info

# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicas }}
  template:
    spec:
      containers:
        - name: api
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          ports:
            - containerPort: {{ .Values.port }}
          env:
            - name: LOG_LEVEL
              value: {{ .Values.logLevel | quote }}
설치 전 렌더 + 검증·bash
# stdout 으로 렌더 (클러스터 접촉 없음)
helm template my-release ./pippa-chart

# values override 로 렌더
helm template my-release ./pippa-chart -f prod-values.yaml

# 렌더 후 K8s schema 로 검증
helm template my-release ./pippa-chart | kubeconform -summary -strict

# Chart lint
helm lint ./pippa-chart
환경별 값 override·yaml
# prod-values.yaml
replicas: 10
logLevel: warn
image:
  tag: '1.0.42'

External links

Exercise

하드코딩된 값 (replica, image tag, env) 가진 Kubernetes manifest 골라. values.yaml 가진 1-template Helm chart 로 변환. 두 values 파일 (dev + prod) 로 helm template 렌더 후 출력 diff. 두 렌더 다 kubeconform 으로 검증. '한 chart, 두 배포' 패턴이 전체 포인트.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.