기록이유
- MLOps 공부 목적, https://mlops-for-all.github.io/ 를 기준으로 설치 중 만나게 된 Helm
- 사내 k8s 클러스터에서도 Helm Chart를 기반으로 운영되고 있기 때문에 이번 기회에 구조나 사용 방법에 대해 학습함
- 공식 문서(관련 링크 1)의 내용 + 나의 느낌/생각을 혼용해서 기술
Helm이란?
- 'Kubernetes (클러스터) 패키지 관리 도구' 라고 보통 표현됨
- Kubernetes를 사용하려고 생각해보면 여러 개의 yaml 파일을 작성하고 관리하는 게 쉽지 않아 보이는 일 (연습용은 대충하면 되지만 운영용은 제대로 만드는 게 필요하니까...) - 자원(Resource), 각 패키지들의 구성
- 요즘 오픈소스 소프트웨어는 기본적으로 Docker/Docker-compose를 통한 실행 방법을 안내하고 있는데 이와 같이 잘 정의된 차트(Kubernetes의 패키지 느낌으로 부르자)들의 묶음으로 Helm Chart가 공개되어 있음 - 관련 링크 2, 3
- 하나의 Chart 단위는 크게 Templates, Chart, Values로 구성되고, 각각을 디렉토리 트리 내 위치/파일명으로 구분함
(아래 '사용하기'에 상세 내용 설명)
설치하기(Installing Helm)
- 위치(대상) : Kubernetes 클러스터에 대해 'kubectl' 을 사용할 수 있는 Kubernetes의 Client Node(클러스터 구성에 따라 다름)
- 과정 : 공식 문서에 아래 네 가지 방법을 소개하고 있는데 첫번째 옵션을 선택해서 설치해봄
- From The Helm Project > From the Binary Releases
- OS / Helm Version : Ubuntu 20.04 / Linux amd64 3.7.1
- 설치 과정
# 1. Download Helm v3.7.1 wget https://get.helm.sh/helm-v3.7.1-linux-amd64.tar.gz # 2. Unpack it tar -zxvf helm-v3.7.1-linux-amd64.tar.gz # 3. Find the Helm binary in the unpacked directory, and move it to its desired destination sudo mv linux-amd64/helm /usr/local/bin/helm
- From The Helm Project > From Script
- Through Package Managers(like apt, yum, ...)
- Development Builds(You must have a working Go environment)
- From The Helm Project > From the Binary Releases
사용하기(Using Helm)
주요 개념
- Chart
- Helm package
- application/tool/service를 작동시키기 위해 필요한 모든 자원의 정의를 포함하고 있음
- yaml 파일들의 모음집 느낌(내부에 정의된 image들은 Registry에 있으면 됨)
- 비유하자면 Homebrew의 formula, apt의 dpkg, yum의 rpm 파일과 같은 개념으로 보면 됨
- Repository
- chart들이 모여져있고 공유되는 곳
- 오픈소스 소프트웨어에게 github repository가 있고, debian의 dpkg에게 apt repo가 있는 것처럼 helm chart에게도 Repository가 있음
- 쉽게 만들 수 있어서 public/private을 운영하는데 큰 어려움은 없어보이며 대표적으로 Artifacthub(웹 어플리케이션), bitnami/chart(github repository)를 들 수 있음
- Release
- chart라는 원본 패키지를 install 했을 때 만들어진 하나의 instance를 가리키는 말(단위)
- 같은 클러스터에 동일한 Chart를 중복해서 install 하는 경우 배포된 각각을 새로운 Release라고 불러야함
- 버전과는 다른 개념이고, OOP에서 Class와 Instance의 관계를 Chart와 Release로 보면 될 듯
명령어
- helm search [hub|repo] [chartname]
- helm pull chartrepo/chartname
- helm install [releasename] [chartrepo/chartname]
- Sources
- A chart repository(like above)
- A local chart archive
- An unpacked chart directory
- A full URL
- options
- --values
- --set
- Sources
- helm status [releasename]
- helm show values [chartrepo/chartname]
- helm upgrade
- helm rollback
- helm get values
- helm history
- helm uninstall
- helm list [--all]
- helm repo list/add/update/remove
- helm create
- helm package
Charts
- The Chart File Structure
wordpress/ Chart.yaml # A YAML file containing information about the chart LICENSE # OPTIONAL: A plain text file containing the license for the chart README.md # OPTIONAL: A human-readable README file values.yaml # The default configuration values for this chart values.schema.json # OPTIONAL: A JSON Schema for imposing a structure on the values.yaml file charts/ # A directory containing any charts upon which this chart depends. crds/ # Custom Resource Definitions templates/ # A directory of templates that, when combined with values, # will generate valid Kubernetes manifest files. templates/NOTES.txt # OPTIONAL: A plain text file containing short usage notes
- Chart Types : application, library
- The Chart.yaml File
apiVersion: The chart API version (required) name: The name of the chart (required) version: A SemVer 2 version (required) kubeVersion: A SemVer range of compatible Kubernetes versions (optional) description: A single-sentence description of this project (optional) type: The type of the chart (optional) keywords: - A list of keywords about this project (optional) home: The URL of this projects home page (optional) sources: - A list of URLs to source code for this project (optional) dependencies: # A list of the chart requirements (optional) - name: The name of the chart (nginx) version: The version of the chart ("1.2.3") repository: (optional) The repository URL ("https://example.com/charts") or alias ("@repo-name") condition: (optional) A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled ) tags: # (optional) - Tags can be used to group charts for enabling/disabling together import-values: # (optional) - ImportValues holds the mapping of source values to parent key to be imported. Each item can be a string or pair of child/parent sublist items. alias: (optional) Alias to be used for the chart. Useful when you have to add the same chart multiple times maintainers: # (optional) - name: The maintainers name (required for each maintainer) email: The maintainers email (optional for each maintainer) url: A URL for the maintainer (optional for each maintainer) icon: A URL to an SVG or PNG image to be used as an icon (optional). appVersion: The version of the app that this contains (optional). Needn't be SemVer. Quotes recommended. deprecated: Whether this chart is deprecated (optional, boolean) annotations: example: A list of annotations keyed by name (optional).
- You can manage Dependencies manually via the charts/ directory
wordpress: Chart.yaml # ... charts/ apache/ Chart.yaml # ... mysql/ Chart.yaml # ...
Templates and Values
- Go template language 로 쓰여짐 : 동적으로 yaml 을 작성/관리하려면 필수이고 따로 학습해야함
- 적용시점 : Helm이 Chart를 Render 할 때 templates/ 폴더에 있는 모든 파일을 template engine에 통과시킴
- values.yaml과 상호작용을 통해 yaml 내 특정 field들을 동적으로 변경시킴
- 또한 Release, Chart.yaml, Files, Capabilities 내 정보를 사용할 수 있음
The Chart Repository
- index.yaml 파일을 통해 모든 패키지들을 리스팅할 수 있고(GET Method만 가능해도) yaml 파일들을 Server 할 수 있는 HTTP 서버만 있으면 만들 수 있음
- Amazon S3, Google Cloud Storage, Github pages, 개인 소유 웹 서버도 가능
Registries
- docker container를 사용해서 local registry 운영 가능('도커 레지스트리'를 검색했을 때 나오는 이미지와 동일한듯)
- 사내에선 (Repository 포함해서) Nexus를 사용하고 있음
Release's life cycle
The lifecycle for a helm install
1. User runs helm install foo // 'foo' 라는 release를 설치 시작
2. The Helm library install API is called // helm이 install API를 호출
3. After some verification, the library renders the foo templates // helm이 'foo'의 템플릿들이 render(kubectl로 yaml을 apply 하는)
4. The library loads the resulting resources into Kubernetes // helm이 쿠버네티스로 자원 사용을 요청
5. The library returns the release object (and other data) to the client // helm이 release된 객체와 데이터를 client로 반환
6. The client exits // 끝
관련 링크
1. HELM Documentation - https://helm.sh/docs/
Docs Home
Everything you need to know about how the documentation is organized.
helm.sh
2. bitnami/charts github repository - https://github.com/bitnami/charts
GitHub - bitnami/charts: Bitnami Helm Charts
Bitnami Helm Charts. Contribute to bitnami/charts development by creating an account on GitHub.
github.com
3. ArtifactHUB - https://artifacthub.io
Artifact Hub
Find, install and publish Kubernetes packages
artifacthub.io
'배우기' 카테고리의 다른 글
Prometheus + Grafana 설치(Helm Chart 이용) (0) | 2022.02.15 |
---|---|
Kubernetes Cluster(VirtualBox) 만들기 (0) | 2022.01.25 |