본문 바로가기

Helm Repository/GitHub

Github를 helm chart Repository로 활용하기 with chart 패키징

# Github를 HelmChart Repository로 활용하는 방법에 대해서 기술한다.

일단 왜 GitHub을 HelmChart Repository로 활용을 해야 하는지 보면 코드를 공유하고 관리하기가 편하기 때문이다. 로컬에서 helmchart를 만들어서 주야장천 배포를 해도 그건 해당 로컬 pc의 소유자만의 리소스이니까 이 리소스를 git헙 같은 공유 리포지토리에 올리고 같이 쓰면 관리도 편하고 무엇보다 argocd 같은 cd 프로그램과 연동하여 사용할 때 유용할 거 같다.

차근차근 하나씩 알아보자.

1. github에 새로운 Repository 생성과 해당 Repository 접근을 위한 URL을 설정한다.

2. 해당 Repository 접근을 위한 URL을 설정한다.

- Vsit site를 클릭하면 아래와 같이 접속 사이트가 표시된다.

3. Local에 git Repository 생성

- 위에서 생성한 git repository의 주소를 복사한다.

- git clone 명령어를 통해 위에서 복사한 git 저장소를 복제한다.

PS C:\git_hub_repo> git clone https://github.com/Nanninggu/helm-charts-seung-repo.git
Cloning into 'helm-charts-seung-repo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

4. chart 패키징 작업 및 github에 패키지 파일 업로드


PS C:\git_hub_repo\helm-charts-seung-repo> helm package .\seung-helm-chart\
Successfully packaged chart and saved it to: C:\git_hub_repo\helm-charts-seung-repo\seung-helm-chart-0.1.0.tgz

PS C:\git_hub_repo\helm-charts-seung-repo> helm repo index C:\git_hub_repo\helm-charts-seung-repo

PS C:\git_hub_repo\helm-charts-seung-repo> git add .

PS C:\git_hub_repo\helm-charts-seung-repo> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.yaml
        new file:   seung-helm-chart-0.1.0.tgz
        new file:   seung-helm-chart/.helmignore
        new file:   seung-helm-chart/Chart.yaml
        new file:   seung-helm-chart/templates/_helpers.tpl
        new file:   seung-helm-chart/templates/deployment.yaml
        new file:   values-01.yaml
        new file:   values.yaml

PS C:\git_hub_repo\helm-charts-seung-repo> git commit -m "helm repo resource upload"
[master f91c624] helm repo resource upload
 8 files changed, 193 insertions(+)
 create mode 100644 index.yaml
 create mode 100644 seung-helm-chart-0.1.0.tgz
 create mode 100644 seung-helm-chart/.helmignore
 create mode 100644 seung-helm-chart/Chart.yaml
 create mode 100644 seung-helm-chart/templates/_helpers.tpl
 create mode 100644 seung-helm-chart/templates/deployment.yaml
 create mode 100644 values-01.yaml
 create mode 100644 values.yaml

PS C:\git_hub_repo\helm-charts-seung-repo> git push -u origin master
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcm/tlsverify for more information.
info: please complete authentication in your browser...
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcm/tlsverify for more information.
git: 'credential-aws' is not a git command. See 'git --help'.
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 16 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 4.24 KiB | 2.12 MiB/s, done.
Total 12 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/Nanninggu/helm-charts-seung-repo.git
   5f7c3e3..f91c624  master -> master
branch 'master' set up to track 'origin/master'.

5. helm chart를 등록하고 클러스터에 배포

PS C:\git_hub_repo\helm-charts-seung-repo> helm repo add git-repo https://nanninggu.github.io/helm-charts-seung-repo/
"git-repo" has been added to your repositories

PS C:\git_hub_repo\helm-charts-seung-repo> helm repo list
NAME            URL
stable          https://charts.helm.sh/stable
github-stable   https://sjoh0704.github.io/helm-chart/stable
seung-repo      https://Nanninggu.github.io/helm-eks-repository/
bitnami         https://charts.bitnami.com/bitnami
git-repo        https://nanninggu.github.io/helm-charts-seung-repo/

PS C:\git_hub_repo\helm-charts-seung-repo> helm search repo git-repo
NAME                            CHART VERSION   APP VERSION     DESCRIPTION
git-repo/seung-helm-chart       0.1.0           1.16.0          A Helm chart for Kubernetes

PS C:\git_hub_repo\helm-charts-seung-repo> helm install test-test-01 git-repo-01/seung-helm-chart
NAME: test-test-01
LAST DEPLOYED: Fri Mar 10 10:56:54 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

6. 배포 확인, 정상적으로 chart 패키지 파일이 배포된 것을 확인할 수 있다.

PS C:\git_hub_repo\helm-charts-seung-repo> kubectl get pod -n nginx
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-864cc6bbb8-gdvbk   1/1     Running   0          2m7s
nginx-deployment-864cc6bbb8-jvlwg   1/1     Running   0          2m7s
nginx-deployment-864cc6bbb8-xp8mr   1/1     Running   0          2m7s

7. 정리

결국에는 chart package를 통해 패키징 된 파일이 실행되므로, 해당 패키징 폴더에는 모든 리소스가 존재해야 한다.

아래는 패키징 된 폴더의 tree 리스트 예시이다. 해당 폴더가 seung-helm-chart-0.1.0.tgz 파일로 패키징 되고, helm 은 패키징 된 파일에서 values.yaml의 정의된 변수들을 templates/deployment.yaml 파일에 맵핑하여 리소스를 생성한다고 보면 된다.

C:\GIT_HUB_REPO\HELM-CHARTS-SEUNG-REPO\SEUNG-HELM-CHART
│  .helmignore
│  Chart.yaml
│  values.yaml
│
├─charts
└─templates
        deployment.yaml
        _helpers.tpl

- 실타래가 점점 풀리는 거 같은 느낌인데, helm 배포 과정에 대해 workflow를 그려보는 작업을 진행하자.

'Helm Repository > GitHub' 카테고리의 다른 글

Github을 Helm Chart Repository로 활용하기  (0) 2023.03.08