티스토리 뷰

Cloud/Cloud Native

Make Helm chart repo

Jacob_baek 2020. 7. 23. 10:40

helm을 신규로 만들게 되면 helm chart repo를 개인적으로 소유해야 하는 경우가 발생되기도 한다.
이러한 경우 어떻게 repo를 만들어서 추가하여 사용할 수 있는지 알아보도록 하자.

helm chart repo on localhost

우선 helm chart를 localhost에서 구동해보자.
물론 chart museum이나 minio(s3)같은 환경을 활용해도 무방하다.
여기서는 간단히 동작을 알아보기 위해 간단히 python webserver로 동작시키는 방식을 사용했다.

우선 여러개의 helm chart가 존재하는 디렉토리로 이동해 다음과 같은 helm chart repo로 동작되게 하기 위한 준비과정을 수행한다.

python http.server 모듈을 이용한 웹서버 구동

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

helm repo로 동작시키기 위한 준비

우선 알아두어야 할 것은 아래 과정은 helm version 3로 진행한 결과이다.
(helm 2.x 에서는 helm serve라는 sub command가 있었는데 3에서는 보이지 않는다.)

helm chart가 존재하는 directory로 이동하여

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ ls -al
total 54
drwxr-xr-x 12 jacob jacob 4096  7월 23 09:56 .
drwxrwxr-x 10 jacob jacob 4096  7월 20 14:18 ..
drwxr-xr-x  4 jacob jacob 4096  4월 24 16:04 jenkins
drwxrwxr-x  2 jacob jacob 4096  7월 23 09:56 keycloak
drwxrwxr-x  4 jacob jacob 4096  5월 20 10:20 mariadb
drwxr-xr-x  4 jacob jacob 4096  4월 24 16:06 minio
drwxr-xr-x  5 jacob jacob 4096  5월 20 13:33 nginx
drwxr-xr-x  5 jacob jacob 4096  5월 20 13:11 nginx-ingress
drwxrwxr-x  5 jacob jacob 4096  4월 29 15:32 prometheus-operator
drwxr-xr-x  4 jacob jacob 4096  2월  5 11:21 sonarqube
drwxr-xr-x  7 jacob jacob 4096  5월 20 12:59 spinnaker

helm repo로 동작시키기 위한 index.yaml 생성과정을 수행한다.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ helm repo index --url "http://localhost:8000" .

위 명령어로 index.yaml파일이 생성된다. 실제 만들어진 index.yaml은 다음과 같다.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ cat index.yaml 
apiVersion: v1
entries:
  jenkins:
  - apiVersion: v1
    appVersion: 2.222.1
    created: "2020-07-23T09:50:56.632540829+09:00"
    description: The leading open source automation server
    digest: 071555acb7e26435e8b30600ad511816025c3fec1d4d97e93a5ea26136fc80ee
    home: https://jenkins.io/
    icon: https://bitnami.com/assets/stacks/jenkins/img/jenkins-stack-110x117.png
    keywords:
    - jenkins
    - ci
    - cd
    - http
    - web
    - application
    maintainers:
    - email: containers@bitnami.com
      name: Bitnami
    name: jenkins
    sources:
    - https://github.com/bitnami/bitnami-docker-jenkins
    urls:
    - http://localhost:8000/jenkins-5.0.7.tgz
    version: 5.0.7
  mariadb:
  - apiVersion: v1
    appVersion: 10.3.22
    created: "2020-07-23T09:50:56.636740797+09:00"
    deprecated: true
    description: DEPRECATED Fast, reliable, scalable, and easy to use open-source
      relational database system. MariaDB Server is intended for mission-critical,
      heavy-load production systems as well as for embedding into mass-deployed software.
      Highly available MariaDB cluster.
    digest: 8f91980656568074178e2c02ad808b1db124f244ceb19d3850776c7feac80184
    home: https://mariadb.org
    icon: https://bitnami.com/assets/stacks/mariadb/img/mariadb-stack-220x234.png
    keywords:
    - mariadb
    - mysql
    - database
    - sql
    - prometheus
    name: mariadb
    sources:
    - https://github.com/bitnami/bitnami-docker-mariadb
    - https://github.com/prometheus/mysqld_exporter
    urls:
    - http://localhost:8000/mariadb-7.3.14.tgz
    version: 7.3.14
  minio:
  - apiVersion: v1
    appVersion: 2020.4.23
    created: "2020-07-23T09:50:56.63848049+09:00"
    description: MinIO is an object storage server, compatible with Amazon S3 cloud
      storage service, mainly used for storing unstructured data (such as photos,
      videos, log files, etc.)
    digest: d8dd1c3e4db7a640d39f0c59ce09a4f78d691d73556e65bb2fe57c71492e47a2
    home: https://min.io
    icon: https://bitnami.com/assets/stacks/minio/img/minio-stack-220x234.png
    keywords:
    - minio
    - storage
    - object-storage
    - s3
    - cluster
    maintainers:
    - email: containers@bitnami.com
      name: Bitnami
    name: minio
    sources:
    - https://github.com/bitnami/bitnami-docker-minio
    urls:
    - http://localhost:8000/minio-3.3.6.tgz
    version: 3.3.6
  prometheus-operator:
  - apiVersion: v1
    appVersion: 0.37.0
    created: "2020-07-23T09:50:56.660246559+09:00"
    dependencies:
    - condition: kubeStateMetrics.enabled
      name: kube-state-metrics
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 2.6.*
    - condition: nodeExporter.enabled
      name: prometheus-node-exporter
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 1.9.*
    - condition: grafana.enabled
      name: grafana
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 5.0.*
    description: Provides easy monitoring definitions for Kubernetes services, and
      deployment and management of Prometheus instances.
    digest: ad6df76741d95155a529f8c21714544d8d91c2bc9ce90059df83eb9e62fb9662
    home: https://github.com/coreos/prometheus-operator
    icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/assets/prometheus_logo-cb55bb5c346.png
    keywords:
    - operator
    - prometheus
    maintainers:
    - name: vsliouniaev
    - name: bismarck
    - email: gianrubio@gmail.com
      name: gianrubio
    name: prometheus-operator
    sources:
    - https://github.com/coreos/kube-prometheus
    - https://github.com/coreos/prometheus-operator
    - https://coreos.com/operators/prometheus
    urls:
    - http://localhost:8000/prometheus-operator-8.12.3.tgz
    version: 8.12.3
  sonarqube:
  - apiVersion: v1
    appVersion: 7.9.2
    created: "2020-07-23T09:50:56.668574001+09:00"
    dependencies:
    - condition: postgresql.enabled
      name: postgresql
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 8.2.0
    - condition: mysql.enabled
      name: mysql
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 0.6.0
    description: SonarQube is an open sourced code quality scanning tool
    digest: 7b13473faa03fbf1eb9c318a15edbdc04b6e95a68f0c8671ed0738092333c6ed
    home: https://www.sonarqube.org/
    icon: https://www.sonarqube.org/assets/logo-31ad3115b1b4b120f3d1efd63e6b13ac9f1f89437f0cf6881cc4d8b5603a52b4.svg
    keywords:
    - coverage
    - security
    - code
    - quality
    maintainers:
    - email: rjkernick@gmail.com
      name: rjkernick
    - email: tsiddique@live.com
      name: tsiddique
    name: sonarqube
    sources:
    - https://github.com/SonarSource/docker-sonarqube
    urls:
    - http://localhost:8000/sonarqube-3.4.0.tgz
    version: 3.4.0
  spinnaker:
  - apiVersion: v1
    appVersion: 1.16.2
    created: "2020-07-23T09:50:56.672629177+09:00"
    dependencies:
    - condition: redis.enabled
      name: redis
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 3.8.0
    - condition: minio.enabled
      name: minio
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: 1.6.3
    description: Open source, multi-cloud continuous delivery platform for releasing
      software changes with high velocity and confidence.
    digest: 851b046573ec12d63c4197a467eab91c9b96bdda3adb68ec1ba51f786c28768a
    home: http://spinnaker.io/
    icon: https://pbs.twimg.com/profile_images/669205226994319362/O7OjwPrh_400x400.png
    maintainers:
    - email: viglesias@google.com
      name: viglesiasce
    - email: ezimanyi@google.com
      name: ezimanyi
    - email: hello@dwardu.com
      name: dwardu89
    - email: username.taken@gmail.com
      name: paulczar
    name: spinnaker
    sources:
    - https://github.com/spinnaker
    - https://github.com/viglesiasce/images
    urls:
    - http://localhost:8000/spinnaker-1.23.3.tgz
    version: 1.23.3
generated: "2020-07-23T09:50:56.626753977+09:00"

해당 디렉토리에 존재하는 각 helm chart들을 search가 가능하도록 yaml 형태로 정보를 생성한다.
필히 알아두어야 하는것은 각 urls에는 tgz로 압축된 helm chart가 존재한다.
이 말인즉슨, package 과정을 거치지 않으면 tgz 파일이 없고 정상적인 repo 기능을 수행하지 못한다는 뜻이다.

NOTE
만약 package 과정을 거치지 않고 install을 수행해보면 다음과 같이 fail 상황이 발생되고

jacob@jacob-laptop:~/workspace/k8s-templates$ helm install sonar jacobhelm/sonarqube
Error: failed to download "jacobhelm/sonarqube" (hint: running `helm repo update` may help)

해당 helm chart repo의 로그를 확인해보면

127.0.0.1 - - [23/Jul/2020 10:22:07] code 404, message File not found
127.0.0.1 - - [23/Jul/2020 10:22:07] "GET /sonarqube-3.4.0.tgz HTTP/1.1" 404 -

에러가 발생됨을 확인할 수 있다.

다음으로는 압축파일을 생성한다.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ helm package spinnaker/
Successfully packaged chart and saved it to: /home/jacob/workspace/k8s-templates/helmcharts/spinnaker-1.23.3.tgz

이제 repo를 helm repo add 명령어를 이용하여 추가해보자.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ helm repo add jacobhelm http://localhost:8000
"jacobhelm" has been added to your repositories

NOTE
만약 index 생성을 하지 않고 바로 추가하려 하면 다음과 같이 index.yaml 파일을 요구하니 필히 생성하고 repo를 추가해야 한다.

jacob@jacob-laptop:~$ helm repo add jacobtest http://127.0.0.1:8000
Error: looks like "http://127.0.0.1:8000" is not a valid chart repository or cannot be reached: failed to fetch http://127.0.0.1:8000/index.yaml : 404 File not found

이제 생성된 repo를 확인해보자. 신규로 생성한 jacobhelm이 확인되는것을 알수 있다.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ helm repo list
NAME            URL                                             
stable          https://kubernetes-charts.storage.googleapis.com
mattermost      https://helm.mattermost.com                     
bitnami         https://charts.bitnami.com/bitnami              
codecentric     https://codecentric.github.io/helm-charts       
stevehipwell    https://stevehipwell.github.io/helm-charts/     
jacobhelm       http://localhost:8000

실제 search를 해보면 다음과 같이 추가했던 chart중 하나를 확인해볼수 있다.

jacob@jacob-laptop:~/workspace/k8s-templates/helmcharts$ helm search repo spinnaker
NAME                   CHART VERSION    APP VERSION    DESCRIPTION                                       
jacobhelm/spinnaker    1.23.3           1.16.2         Open source, multi-cloud continuous delivery pl...
stable/spinnaker       1.23.3           1.16.2         Open source, multi-cloud continuous delivery pl...

Github 혹은 GitLab 등과 같은 public git repository에 추가

위 내용을 기반으로 Github에 repo를 생성해보도록 하자.
여기서 url설정만이 다르고 나머지는 동일하다고 보면 된다.

public 한 url을 제공하기 위해서는 public한 도메인이 필요하다. 감사하게도 Github의 경우 public page를 github.io로 제공하고 있고 이를 설정 변경으로 사용할 수 있다.

github repo를 하나 생성한다. (편한 이름으로 repo를 생성을 한다.)

이제 새로 생성된 github repo에 저장할 파일들을 생성할 디렉토리를 생성하자.

mkdir jacobhelm
cd jacobhelm

앞서 localhost에 생성했듯이 동일한 과정을 거쳐 repo 서비스를 위한 index.yaml 및 chart에 대한 tgz 파일을 생성한다.

# 자신만의 helm chart를 생성 혹은 fetch 한다.
helm fetch --untar stable/[helm chart name]

# helm chart의 tgz 파일 생성
helm package [helm chart name]

# index.yaml 파일 생성
helm repo index --url "https://jacobbaek.github.io/helmcharts" .

이제 작성된 파일들을 github에 push 하자.

(앞서 새로 repo를 새로 생성했기 때문에 github 주소에 대한 인지가 안되어 있을것이다. 아래와 같은 작업을 통해 git 주소를 추가하자.)

git add .
git commit -m "first commit"
git remote add origin https://github.com/jacobbaek/helmcharts.git
git push --set-upstream origin master

마지막으로 web page로 접속이 가능하도록 하기 위해 아래와 같은 github page 설정을 진행한다.

우선 settings로 이동한다.

아래로 스크롤 해보면 아래와 같은 github page에 대한 설정을 확인할 수 있다.

Branch를 선택하고 설정을 완료한다.

이제 다음 명령을 통해 정상적으로 helm chart가 출력되는지 확인해보자.

jacob@jacob-laptop:~$ helm repo add jacobhelm https://jacobbaek.github.io/helmcharts
"jacobhelm" has been added to your repositories

jacob@jacob-laptop:~$ helm search repo jacobhelm
NAME                  CHART VERSION    APP VERSION    DESCRIPTION                                      
jacobhelm/ldap-php    0.1.4            1.0.0          Web-based LDAP browser to manage your LDAP server

실제 적용된 설정을 확인하고자 한다면 아래 링크를 참고하여 github에 repo를 만들어보자.

NOTE
참고로 각 chart는 별도로 관리하는 것을 추천한다. (유지보수측면에서 별도로 관리되는것이 좋다.)
하여 charts 라는 디렉토리에 임시로 clone 하여 package 작업을 거치도록 해놓았다.

참고로 GitLab은 API를 통해 직접 tgz(helm chart package)를 업로드할수 있도록 하고 repo 주소를 제공하여 바로 repo로 등록하여 사용할 수 있도록 제공하고 있다. 버전이 14.1부터 가능하니 버전확인을 하고 사용해야 한다.

참고사이트

'Cloud > Cloud Native' 카테고리의 다른 글

Octant  (0) 2020.10.02
nginx ingress with namespace  (0) 2020.08.24
Accident for deleting pvc  (0) 2020.06.23
minikube start in WSL2  (0) 2019.12.07
kubernetes troubleshooting  (0) 2019.11.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함