What is the HELM ?
Helm이란 k8s 패키지 관리를 도와주는 매니저이다. 공식사이트 (nodejs의 npm, python의 pip, MacOS의 brew와 같은 역할이라고 할 수 있다) Helm을 이용하면 k8s에 쉽게 그리고 빠르게 원하는 패키지들을 설치하고, 관리(업데이트, 배포 등) 할 수 있다.
기본이 되는 필수개념을 소개하자면, Chart, Repository, Release 3가지가 있다.
Chart:Helm의 단위가 되는 패키지이며,application이 구동되기 위해 필요한 여러 리소스들이 포함되어 있다.Repository:chart가 저장되고 공유되는 곳이다.docker로 생각한다면dockethub의 역할이라고 할 수 있다. 대표적인repo로는 bitnami(https://bitnami.com/stacks)가 있다.Release:Helm이 실행되는chart instance이다. 일반적으로 동일한chart를 여러번 실행(설치) 가능하고,chart,config들이 결합되어 실행된다.
❖ Helm을 실행하기 위해서는 k8s가 필수적으로 설치되어 있어야 정상적으로 동작한다. (k8s cluster, kubeconfig)
Basic tree of the helm chart
helm을 이용해서 새로운 chart를 생성하게 되면 기본구조를 가지고 있는 chart가 생성된다. 그 tree 구조는 아래와 같다.
|____ Chart.yaml
|____ values.yaml
|____ charts/
|____ templates/
|____ NOTES.txt
|____ _helpers.tpl
|____ deployment.yaml
|____ ingress.yaml
|____ service.yaml
...
Chart.yaml: chart 정보를 정의 (name, description, version 등. 자세한 항목은 공식문서 참조)values.yaml: k8s template yaml에 적용하는 dynamic value들을 정의charts: dependency chart를 저장하는 directorytemplates: k8s resource template이 저장되는 directoryNOTES.txt: chart 설치후 출력할 메시지를 정의_helpers: templates 폴더에서 사용할 변수들을 정의deployment.yaml,ingress.yaml,service.yaml: k8s에 실행할 resource template
기본 Command
✓ helm create [name] 새로운 helm chart를 생성
✓ helm search helm hub/repository에서 chart 검색
✓ helm update apt update와 비슷한 역할. chart 정보를 최신화
✓ helm install k8s에 helm chart 설치 (kubectl apply와 비슷)
✓ helm uninstall 설치된 release를 삭제
✓ helm list k8s에 install된 모든 release를 리스트업
✓ helm show chart에 대한 정보 보기
✓ helm repo chart repository 추가, 업데이트 등
✓ helm package [name] 현재 폴더에 chart archive 생성 ([name]-[version].tgz 포맷으로 생성)
✓ helm history [name] release history를 확인
✓ helm hellback [name] [revision] 입력한 revision으로 rollback 한다
✓ helm install [name] . --dry-run --debug helm chart를 설치하는 시뮬레이션을 실행하여 실제로 어떤 작업이 수행될지 미리 확인할 수 있다
Helm install with dynamic variable: chart.yaml, values.yaml
templates 이하의 yaml 파일을 작성할때, 그 내부 변수들을 values.yaml에서 읽어와 동적으로 injection 시켜줄 수 있다. helm을 사용하는 이유라고 해도 과언이 아닌 기능이다.
Chart.yaml, values.yaml 파일을 아래처럼 정의하고, templates 폴더 이하에 deployment.yaml 아래처럼 작성하게 되면,
## Chart.yaml
apiVersion: v2
name: myapp
description: myapp nginx description
type: application
version: 0.0.1
appVersion: 1.0.0## values.yaml
replicaCount: 2
image:
repository: nginx
tag: 1.2.3
pullPolicy: ifNotPresent
pullSecret:
service:
type: NodePort## deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "deploy-{{ .Release.Name }}" # install 할때에 지정하는 name이 주입된다.
# 특정값으로 지정해둘 경우 같은 값이 들어갈수 있기 때문에 name을 따라가도록 설정하는것에 주의
spec:
replicas: {{ .Values.replicaCount }} # values에서 replicaCount를 읽어와 replicas: 2 로 생성된다.
selector:
matchLabels:
app: "{{ .Chart.Name }}" # chart에서 name을 읽어온다. 즉, app: myapp
template:
metadata:
labels:
app: "{{ .Chart.Name }}" # chart에서 name을 읽어온다. 즉, app: myapp
spec:
containers:
- image: "{{ .Values.image.repository }}" # values에서 repository을 읽어온다. 즉, image: nginx
imagePullPolicy: "{{ .Values.image.pullPolicy }}" # values에서 pullPolicy을 읽어온다. 즉, imagePullPolicy: ifNotPresent
name: "{{ .Chart.Name }}" # chart에서 name을 읽어온다. 즉, app: myapp
ports:
- containerPort: 80- https://helm.sh/
- https://helm.sh/docs/topics/charts/