컨테이너 오케스트레이션

Devops Day 55 (5.23) 컨테이너 오케스트레이션_helm 패키지 매니저

Jackykim 2023. 5. 24. 03:41

helm 쿠버네티스 패키지 매니저
우리는 이미 앞서 apt나 homebrew과 같이 애플리케이션 실행 파일을 제공하는 패키지 매니저, 혹은 npm과 같이 node.js 관련 모듈을 제공하는 패키지 매니저를 사용해 보았습니다.

helm은 쿠버네티스 워크로드를 하나로 묶어서 패키지 형태로 만들고, 배포하고, 설치할 수 있는 도구입니다. 즉, 쿠버네티스 패키지 매니저입니다.

 

차트, 저장소, 릴리스

- helm에서는 패키지를 차트라고 부릅니다.

- helm에서는 패키지가 저장되어 있는 공간을 저장소라고 부릅니다.

- 차트를 설치하여, 쿠버네티스 클러스터에 구동될 때, 차트의 인스턴스를 릴리스라고 부릅니다.

 

Hands-on: helm으로 Jenkins 설치하기
공식 Jenkins 차트 설명을 따라 설치를 진행해 봅시다. (ArtifactHub는 helm의 차트를 찾아볼 수 있는 사이트입니다)

0. Helm 설치
0.1 curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null

0.2 sudo apt-get install apt-transport-https --yes

0.3 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list

0.4 sudo apt-get update

0.5 sudo apt-get install helm
참조 : https://helm.sh/docs/intro/install/


1. Get Repo Info : repository 정보를 업데이트하세요.

1.1 helm repo add jenkins https://charts.jenkins.io
1.2 helm repo update

2. Install Chart : helm install jk jenkins/jenkins
와 같이 설치하세요. jk는 릴리스(인스턴스) 이름입니다.
2.1 helm install jk jenkins/jenkins

2.2. Get your 'admin' user password by running:

  kubectl exec --namespace default -it svc/jk-jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo (ZCyV8b37TIsYnX3BUn7lsW)

2.3 Get the Jenkins URL to visit by running these commands in the same shell:

  echo http://127.0.0.1:8080

kubectl --namespace default port-forward svc/jk-jenkins 8080:8080

2.4 Login with the password from step 1 and the username: admin

2.5 Configure security realm and authorization strategy

2.6 Use Jenkins Configuration as Code by specifying configScripts in your values.yaml file, see documentation: http://127.0.0.1:8080/configuration-as-code and examples: https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos

- helm show values jenkins/Jenkins -> Jenkins 내용 확인 가능
- kubectl get all / kubectl get pv -> Jenkins 차트 구성 확인

Jenkins를 종료 혹은 삭제하려면 helm uninstall 명령을 이용합니다

 

참고 : https://artifacthub.io/packages/helm/jenkinsci/jenkins
참고 : https://www.jenkins.io/doc/book/installing/kubernetes/#install-jenkins-with-helm-v3

 

helm 차트 구성
제공되는 hello-world 차트의 구성을 살펴보세요. 디플로이먼트, 서비스 이렇게 단 두 개의 리소스로만 구성된 차트가 제공됩니다.

 

차트를 만드는 원리는 간단합니다.

1. /templates 디렉토리에 원하는 리소스 명세 파일을 적는다.

2. 템플릿은 말 그대로 "뭔가 내용을 채워 넣어야" 하는 것으로, 빈칸(placeholder)을 곳곳에 삽입할 수 있다.

3. 이 빈칸에는 릴리스 내용을 넣을 수도 있으며, 또는 값을 별도로 정의(values.yaml)해서 넣을 수도 있다.

 

1.1 helm template ./hello-world -> template 확인 가능 합니다.

2.1 helm template ./hello-world | kubectl apply -f - && kubectl port-forward services/$(kubectl get svc -l release=hello-world -o jsonpath='{.items[0].metadata.name}') 8080:80 -> template 포트 포워딩

3.1 kubectl port-forward service/release-name-hello-world 8080:80

참고 문서 : https://www.baeldung.com/ops/kubernetes-helm
참고 문서 : https://helm.sh/ko/docs/chart_template_guide/getting_started/