helm 개요
Helm docs kor : https://helm.sh/ko/docs/ helm 설치 및 상세한 설명 참고인프런 강의 : https://www.inflearn.com/course/대세-쿠버네티스-helm
helm은 여러 차트(템플릿 파일들의 집합) 를 관리하는 도구이다. 차트가 저장된 차트 저장소를 통해 필요한 애플리케이션들을 빠르게 설치 가능하다.
helm v2 를 사용하고 있다면 k8s cluster 안에 Tiller 라는 별도의 API Service 를 설치해야 하지만
2018년 helm이 CNCF 에 합류되고 helm v3 가 출시되면서 Tiller 설치 없이 바로 helm client 를 통해 k8s cluster 에 서비스 설치가 가능해졌다.
helm을 사용하면 각 환경별 템플릿을 작성할 필요 없이변경될수 있는 설정을 변수화 하여 최소한의 템플릿 으로 관리할 수 있도록 지원한다.
또한 많은 오픈소스 제품들이 k8s cluster 안에서 동작할 수 있도록 helm 템플릿 과 가이드를 제공한다.
helm 허브 : https://artifacthub.io/ 오픈소스 회사 혹은 개인이 helm 을 통한 서비스 설치 가이드를 제공,Helm Chart Repository 에서 원하는 오픈소스의 템플릿을 검색, 다운받을 수 있다.
helm repo 명령을 통해 로컬 repo 에 차트 저장하고helm intall 명령을 통해 로컬 repo 에 저장된 차트를 k8s cluster 에 배포한다.
helm은 Go templates 문법을 기반으로 구문작성이 되기에 약간의 스크립트성 지식이 필요하다. 즉 helm은 여러개로 흩어져 있는 문서들을 Go templates 을 사용하여 하나의 template 파일로 구성하고 배포하는 클라이언트 프로젝트이다
helm 차트 설치 간단한 helm 차트를 설치하고 조회, 삭제 등의 명령어를 사용해보자.
보통 helm은 누군가 잘 만들어 놓은 차트를 다운받아 사용하는데 웹상에 등록된 stable repo 로부터 다운 가능하다.helm 허브 에서 tomcat 검색후 bitnami 에서 제공하는 tomcat 차트 를 확인해볼 수 있다.
bitnami 의 tomcat 차트를 사용하려면 먼저 bitnami repository를 설정해야 한다.
helm 허브 의 repository를 사용하는 명령은 아래와 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 helm repo add bitnami https://charts.bitnami.com/bitnami helm repo list helm repo update helm search repo bitnami | grep tomcat helm repo delete bitnami
helm install 명령을 사용해 bitnami repository에 있는 톰켓 차트를 설치
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 $ helm install my-tomcat bitnami/tomcat --version 10.4.3 --set persistence.enabled=false NAME: my-tomcat LAST DEPLOYED: Mon Sep 19 13:51:12 2022 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: CHART NAME: tomcat CHART VERSION: 10.1.10 APP VERSION: 10.0.16 ** Please be patient while the chart is being deployed ** 1. Get the Tomcat URL by running: NOTE: It may take a few minutes for the LoadBalancer IP to be available. Watch the status with: 'kubectl get svc --namespace default -w my-tomcat' export SERVICE_IP=$(kubectl get svc --namespace default my-tomcat --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}") echo "Tomcat URL: http://$SERVICE_IP:/" echo "Tomcat Management URL: http://$SERVICE_IP:/manager" 2. Login with the following credentials echo Username: user echo Password: $(kubectl get secret --namespace default my-tomcat -o jsonpath="{.data.tomcat-password}" | base64 --decode)
영속 저장공간 찾기를 해제해야 추가설정없이 구동 가능하기에 persistence.enabled=false 변수를 지정
k8s Service 의 타입이 LoadBalancer 임을 확인하고 포워딩된 포트로 접속하면 실행중인 톰켓에 접속 가능하다.
1 2 3 4 $ kubectl get svc my-tomcat NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-tomcat LoadBalancer 10.96.116.107 <pending> 80:31567/TCP 111s
helm list, helm status, helm uninstall 명령을 통해 배포된 차트 조회, 상태출력, 삭제를 할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 $ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION my-tomcat default 1 2022-09-19 13:51:12.818956 +0900 KST deployed tomcat-10.1.10 10.0.16 $ helm status my-tomcat NAME: my-tomcat LAST DEPLOYED: Mon Sep 19 13:51:12 2022 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: CHART NAME: tomcat CHART VERSION: 10.1.10 APP VERSION: 10.0.16 ** Please be patient while the chart is being deployed ** 1. Get the Tomcat URL by running: NOTE: It may take a few minutes for the LoadBalancer IP to be available. Watch the status with: 'kubectl get svc --namespace default -w my-tomcat' export SERVICE_IP=$(kubectl get svc --namespace default my-tomcat --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}") echo "Tomcat URL: http://$SERVICE_IP:/" echo "Tomcat Management URL: http://$SERVICE_IP:/manager" 2. Login with the following credentials echo Username: user echo Password: $(kubectl get secret --namespace default my-tomcat -o jsonpath="{.data.tomcat-password}" | base64 --decode) $ helm uninstall my-tomcat release "my-tomcat" uninstalled
템플릿 vs 인스턴스 helm차트를 배포하기 전 파일을 템플릿, helm차트를 배포하고 업로드된 템플릿을 인스턴스라 한다.
helm 차트 위와 같이 helm 허브 에 공개된 repo 를 통해 별도의 수정없이 바로 서비스를 설치해도 되지만
좀더 디테일한 설정이 필요할 경우 chart 파일을 직적 다운받아 설정후 배포시킬 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 helm pull bitnami/tomcat --version 10.4.3 tar -xf ./tomcat-10.4.3.tgz helm install my-tomcat ./tomcat -f values.yaml kubectl get svc my-tomcat helm list helm status my-tomcat helm uninstall my-tomcat kubectl get pods
내부 구성은 다음과 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 tree
templates/deployment.yaml 파일을 보면 아래와 같은데 해당파일이 실질적으로 tomcat 를 배포하는 템플릿 파일이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 {{ if (or (not .Values.persistence.enabled) (eq .Values.deployment.type "deployment" )) }} apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}kind: Deployment metadata: name: {{ template "common.names.fullname" . }} namespace: {{ .Release.Namespace }} labels: {{- include "common.labels.standard" . | nindent 4 }} {{- if .Values.commonLabels }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} {{- end }} {{- if .Values.commonAnnotations }} annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }} strategy: {{- include "common.tplvalues.render" (dict "value" .Values.updateStrategy "context" $ ) | nindent 4 }} template: metadata: labels: {{- include "common.labels.standard" . | nindent 8 }} {{- if .Values.podLabels }} {{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }} {{- end }} {{- if .Values.podAnnotations }} annotations: {{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }} {{- end }} spec: {{- include "tomcat.pod" . | nindent 6 }} {{- end }}
다양한 변수들이 정의되어 있는데 위에서 톰켓 영속성 disable 시에 사용했던 persistence.enabled 변수역시 정의되어 있다.
template 디렉토리에는 deployment 설정 뿐 아니라 어플리케이션 구동시 필요한 service, configMap 등의 k8s 리소스들이 추가로 정의될 수 있다.
values.yaml 를 확인하면 deployment 에 들어갈 각종 변수들의 default 값들이 정의되어 있다.
Chart.yaml 과 README.md 파일은 차트를 helm 허브 에 올렸을때 출력되는 내용임으로 해다 차트에 대한 정보가 자세하게 작성되어 있다.
NOTES.txt 에는 배포후 출력문구가 적혀있는것을 확인 가능하다.
helm create, helm install 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 helm create mychart tree helm install mychart . -f values_prod.yaml -set configMapData.log =debug
helm create 명령으로 직접 helm 차트 생성이 가능하다.
helm install 명령으로 생성된 helm 차트를 배포한다.-f, -set 명령어로 실행시 할당할 변수가 정의된 파일을 지정할 수 있으며-set 옵션의 경우 설정파일보다 더 우선시하기때문에 특정 변수에 대해서 우선순위를 높히고 싶을 때 사용할 수 있다.
helm show, helm template helm show 명령을 통해 차트내의 파일들을 출력할 수 있다.
cat 명령어와 동일하나 주석 제외하고 출력한다.
1 2 3 4 $ helm show values # values.yaml 조회 $ helm show chart # chart.yaml 조회 $ helm show readme . # README.md 조회 $ helm show all . # 모든파일 조회
deployment.yaml 의 설정 대기중인 변수들을 values 가 적용된 상태로 출력하고 싶다면helm template 커맨드를 사용하면 된다.
배포전 helm template 명령을 통해 절저히 검증 후 배포해야한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 $ helm template mychart . # Source: mychart/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: mychart labels: helm.sh/chart: mychart-0.1.0 app.kubernetes.io/name: mychart app.kubernetes.io/instance: mychart app.kubernetes.io/version: "1.16.0" app.kubernetes.io/managed-by: Helm
-f, -set 옵션을 사용해 변수를 직접 정의할 수 있다.
1 $ helm template mychar . -f test-values.yaml
helm status, helm get 배포된 차트의 상태값을 확일하고 싶을때 helm status 명령을 사용하고 배포된 차트의 설정값을 확일하고 싶을때 helm get 명령을 사용한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 인스턴스 실행 상태, 네임스페이스, 배포횟수 등 확인가능 $ helm status mychart NAME: mychart LAST DEPLOYED: Thu Sep 22 16:15:41 2022 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/ ... # template 폴더안 yaml 파일 출력, 각종 가 적용된 이후의 내용이 출력된다. $ helm get manifest mychart # 배포시 `-f`, `-set` 등의 옵션로 최종 설정된 `value` 값들을 출력 # 아무런 옵션없이 배포한 상태라면 `helm get value` 는 공백을 출력한다. $ helm get value mychart # NOTES.txt 출력, value 가 적용된 이후의 문구가 출력된다. $ helm get notes mychart # 위 3가지 정보 한번에 출력 $ helm get all mychart
helm upgrade 템플릿 파일을 업데이트하고 인스턴스에도 동기화 되기를 원한다면helm upgrade 명령어 사용
1 $ helm upgrade mychart . -n default
명령어 요약
명령어
설명
helm create <CHART_NAME>
차트를생성한다.
helm install <CHART_NAME>
차트를 설치한다.
helm list (-n <NAMESPACE>)
(네임스페이스의) 차트 목록을 조회한다.
helm template <CHART_NAME>
차트 랜더링(values.yaml이 적용된 템플릿 생성)을 수행한다.
helm upgrade <CHART_NAME> <CHART_PATH>
설치한 차트에 대해 수정한 values.yaml을 적용한다.
helm status <CHART_NAME>
차트 배포상태를 확인한다.
helm delete <CHART_NAME>
차트를 삭제한다.
helm repo add <REPO_NAME> <URL>
차트를 저장하는 원격 저장소를 추가한다.
helm repo update
원격 저장소를 최신 상태로 업데이트한다.
helm repo list
원격 저장소 목록을 조회한다.
helm search repo <REPO_NAME>
원격 저장소 내의 차트 목록을 조회한다.
helm fetch <REPO_NAME>/<CHART_NAME>
원격 저장소의 차트를 로컬 디렉토리로 다운로드한다.
helm upgrade <CHART_NAME>
원격 저장소의 차트를 로컬 디렉토리로 다운로드한다.