본 문서는 2023년 7월에 작성된 문서입니다.

Artifact Hub는 Kubernetes 커뮤니티의 중앙 리소스 저장소로서, 다양한 애플리케이션 패키지, Helm 차트, OPA 정책, Falco 규칙 등을 검색, 탐색 및 공유할 수 있는 오픈 소스 플랫폼입니다. 즉 Artifact Hub는 사용자와 Helm chart repository를 중개하는 역할을 수행하고 있습니다. 오늘은 Helm package를 Artifact Hub에 등록하여 사용하는 방법에 대하여 정리하였습니다.

 

시작하기 전에

Helm chart repository는 github으로 구성하고 Artifact Hub를 이용하여 Helm chart repository와 중개하도록 구성하였습니다.

 

1. github repo 생성

자신의 github에 helm package를 등록할 수 있도록 github repository를 생성하여 줍니다. 저는 repository 명을 test-nginx라고 명시하였습니다.

 

2. 실습 디렉토리 구성

helm-nginx 디렉토리는 실제 helm chart를 작성하였고 test-nginx는 방금 생성한 github repo를 clone 한 디렉토리입니다. helm-nginx 디렉토리에서 작성된 helm chart를 test-nginx에 package 하여 github에 push를 할 예정입니다.

 

3. Helm chart 작성

helm-nginx 디렉토리로 이동하여 helm chart를 간단하게 구성도록합니다. 이번 실습에서는 불필요한 부분은 제거하고 values.yaml파일과 templates/deployment.yaml만 작업하였습니다.

values.yaml

위에 사진과 내용이 동일합니다. (실습 복붙용)

name: test-nginx

replicas: 1

imageTag: latest

resources:
  requests:
    memory: "64Mi"
    cpu: "250m"
  limits:
    memory: "128Mi"
    cpu: "500m"

deployment.yaml

위에 사진과 내용이 동일합니다. (실습 복붙용)

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ .Values.name }}
  name: {{ .Values.name }}
spec:
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        resources:
{{ toYaml .Values.resources | indent 10 }}

정상적으로 작성되었는지 확인

--dry-run 옵션을 통해 실제로 생성하지 않고 helm이 잘 작성되었는지 확인할 수 있습니다.

$ helm install test --dry-run .
# 결과
NAME: test
LAST DEPLOYED: Sat Jul  1 13:51:49 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-nginx/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-nginx
  name: test-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-nginx
  template:
    metadata:
      labels:
        app: test-nginx
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        resources:
          limits:
            cpu: 500m
            memory: 128Mi
          requests:
            cpu: 250m
            memory: 64Mi

 

4. helm package 생성

상위 디렉토리인 helm 디렉토리로 이동하여 helm package 명령을 수행하여 package를 생성합니다.

# helm package 생성
$ helm package ./helm-nginx/ --destination ./test-nginx

# helm index 생성
$ helm repo index ./test-nginx

# 결과 확인
$ ls -al ./test-nginx/
total 24
drwxr-xr-x 3 hsw hsw 4096 Jul  1 14:52 .
drwxr-xr-x 4 hsw hsw 4096 Jul  1 14:27 ..
drwxr-xr-x 8 hsw hsw 4096 Jul  1 14:53 .git
-rw-r--r-- 1 hsw hsw    6 Jul  1 14:27 README.md
-rw-r--r-- 1 hsw hsw  799 Jul  1 14:27 helm-nginx-0.1.0.tgz
-rw-r--r-- 1 hsw hsw  397 Jul  1 14:52 index.yaml

 

5. github push

$ git add .
$ git commit -m "create helm package"
$ git push

 

6. github pages 설정

Settings - Pages로 이동하여 다음과 같이 설정합니다. 3번까지 수행한 후 해당 페이지를 새로고침 하면 4번처럼 주소가 나옵니다. 해당 주소를 복사하고 있다가 Artifact Hub 설정에서 사용합니다.

 

7. Artifact Hub에 등록하기

Artifact Hub에 접속하여 로그인합니다.

https://artifacthub.io/

 

Artifact Hub

Find, install and publish Kubernetes packages

artifacthub.io

 

우측 상단 User 아이콘 클릭 후 Control Panel을 선택하여 줍니다.

 

ADD REPOSITORY를 선택하게 되면 다음과 같이 화면이 나오는데 여기서 해당된 값을 입력합니다.

  • Kind : Helm charts
  • Name : 등록될 Repository 이름
  • Display name : 사용자에게 보이는 이름
  • Url : 등록할 github 주소

ADD 버튼을 클릭하여 추가하게 되면 다음과 같이 Repo가 생성됩니다.

Repo 설정이 완료되었다면 일정 시간 간격(약 30분)으로 Repo 스캔을 하게 됩니다. 스캔이 완료되면 해당 Repo를 통하여 helm을 이용해 배포할 수 있습니다.

 

'Kubernetes' 카테고리의 다른 글

kubernetes max pods 개수 수정  (0) 2024.07.31
[Helm] Helm 기본 명령어  (0) 2023.07.15
2023 CKA(Certified Kubernetes Administrator) 취득 후기  (0) 2023.07.01

+ Recent posts