Container Orchestration/Kubernetes

Helm Chart 생성 및 패키징 (gh-pages)

Somaz 2024. 12. 20. 13:25
728x90
반응형

Overview

생성한 Kubernetes Operator를 Helm Chart 생성하고 패키징하여 github gh-pages 브랜치에 hosting 하는 방법에 대해서 알아본다.

https://github.com/somaz94/helios-lb

 

GitHub - somaz94/helios-lb: helios-lb

helios-lb. Contribute to somaz94/helios-lb development by creating an account on GitHub.

github.com

 

Helm에 대한 내용들은 이전 포스팅을 참고하길 바란다.

2022.09.06 - [Container Orchestration/Kubernetes] - Helm 이란? (Kubernetes Package manager)

2023.05.16 - [Container Orchestration/Kubernetes] - Helm Chart 작성방법

2024.11.15 - [Container Orchestration/Kubernetes] - Helm Chart Template 문법

 


Helm Chart 생성 및 패키징

 

Helm chart 생성

 

helm을 먼저 설치한다.

# mac
brew install helm

# linux
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

helm init

# 확인
helm version

 

 

helm create 를 사용해서 chart를 생성할 수 있다.

helm create <chart name>

 

 

helios-lb 기준으로 설명하도록 하겠다. 각 파일에 용도는 다음과 같다.

helios-lb [main|✔] 
13:16 $ tree helm
helm/
├── README.md                  # 차트 사용 방법, 설정 파라미터 문서
└── helios-lb/                 # 메인 차트 디렉토리
    ├── Chart.yaml            # 차트 메타데이터 (버전, 의존성 등)
    ├── crds/                 # CRD 정의 파일
    │   └── heliosconfig.yaml # HeliosConfig CRD 스펙
    ├── templates/            # 쿠버네티스 리소스 템플릿
    │   ├── NOTES.txt        # 설치 후 표시될 사용 안내
    │   ├── _helpers.tpl     # 공통으로 사용되는 템플릿 함수
    │   ├── crd-clenaup-hook.yaml    # CRD 삭제를 위한 Helm hook
    │   ├── customresource/   # CR 템플릿
    │   ├── deployment.yaml   # 컨트롤러 deployment
    │   ├── namespace.yaml    # 네임스페이스 정의
    │   ├── rbac.yaml        # 권한 설정 (Role, RoleBinding)
    │   ├── service.yaml     # 서비스 정의
    │   └── serviceaccount.yaml # 서비스어카운트 정의
    ├── values/              # 사용 사례별 values 파일
    │   ├── basic-values.yaml  # 기본 설정
    │   ├── port-values.yaml   # 포트 기반 설정
    │   └── weight-values.yaml # 가중치 기반 설정
    └── values.yaml          # 기본 values 파일
  • Chart 생성이 끝났다면 패키징을 해보도록 한다.

 

 

Helm 패키징

패키징을 하여 웹 호스팅을 위해 Github Pages를 사용할 수 있다.

GitHub Pages는 GitHub의 특별한 기능으로, gh-pages 브랜치를 자동으로 웹 호스팅해주는 시스템이다. 작동 원리는 다음과 같다.

 

 

1. Github Pages 활성화 과정

# 새로운 gh-pages 브랜치 생성
git checkout --orphan gh-pages

# helm repo 생성
helm package ./helm/helios-lb
helm repo index . --url https://somaz94.github.io/helios-lb/helm-repo

# 필요한 파일만 남기고 커밋
git add index.yaml helios-lb-*.tgz
git commit -m "Add helm chart repository"
git push origin gh-pages

 

 

2. 자동화 과정

GitHub가 gh-pages 브랜치 감지

  • GitHub가 gh-pages 브랜치 감지
  • 자동으로 https://[username].github.io/[repository-name] 주소 할당
  • 브랜치의 내용을 정적 웹사이트로 제공

 

3. Helm Repository 구조

gh-pages branch
├── index.yaml           # 차트 메타데이터 및 버전 정보
└── helios-lb-0.1.0.tgz  # 패키지된 helm 차트

 

 

4. 사용방법

# 레포지토리 추가
helm repo add helios-lb https://somaz94.github.io/helios-lb/helm-repo

# 차트 설치
helm install helios-lb helios-lb/helios-lb

 

 

5. 주의할점

gh-pages 브랜치에는 Repo 파일 말고 어떠한 파일도 있어서는 안된다.

따라서 아래와 같은 방법으로 chart 생성해주면 된다.

# main 브랜치에서 생성
mkdir helm-repo
cd helm-repo
helm package ../helm/helios-lb

# index.yaml
helm repo index . --url https://somaz94.github.io/helios-lb/helm-repo

cd ../
mv helm-repo ../

# gh-pages 브랜치 재생성
git checkout --orphan gh-pages  # 완전히 새로운 브랜치 생성
git rm -rf .                    # 모든 파일 제거
mv ../helm-repo .

git add .
git commit -m "Add Helm chart repository"
git push origin gh-pages

 

 

6. 마무리

이렇게 간단하게 Helm Chart를 만들어서 Repo에 등록 후 호스팅 할 수 있다.

 

 


Reference

https://github.com/somaz94/helios-lb

728x90
반응형