study/devops

helm 패키지 매니저

FYE 2023. 2. 16. 10:40

helm 쿠버네티스 패키지 매니저

 

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

즉,쿠버네티스 애플리케이션을 관리하기 위한 패키지 매니저이다.

 

하나의 애플리케이션 구성이 최소 하나 이상의 파드와 서비스로 구성되어있음을 생각해봤을 때, 별개의 워크로드를 하나하나 적용하기 보다는, 한번에 여러 개의 워크로드가 즉시 배포된다면 간편할 것이다.

 

helm은 쿠버네티스에서 애플리케이션을 쉽게 배포하고 관리하기 위한 도구이다.

helm을 사용하면 애플리케이션을 패키징하여 차트라고 불리는 배포 가능한 패키지로 만들 수 있다.

이러한 차트는 애플리케이션의 모든 구성 요소를 포함하고 있으며, 이를 사용하여 쿠버네티스 클러스터에 배포할 수 있다.

 

또한 helm은 애플리케이션 업데이트, 롤백, 환경변수 설정, 스토리지 관리, 로깅 및 모니터링 등을 위한 다양한 기능을 제공한다.

이를 통해 애플리케이션 배포와 관리의 복잡성을 줄이고, 더욱 효율적이고 안정적인 운영을 가능하게 한다.

 


차트, 저장소, 릴리즈

 

차트(Chart)

애플리케이션을 패키징하는 단위
쿠버네티스 오브젝트들을 정의하는 YAML파일들의 묶음
쉽게 말해 쿠버네티스에서 배포할 애플리케이션을 구성하는 파일들이 포함된 패키지이다.

 

 

저장소(Repository)

패키지가 저장되어 있는 공간 = 차트를 저장하는 공간
HTTP(S)를 통해 액세스 가능하다. 여러 개의 저장소를 사용할 수 있다.

 

 

릴리즈 (Release)

차트를 설치하여, 쿠버네티스 클러스터에 구동될 때, 차트의 인스턴스
특정 차트에 대한 배포를 의미한다.
릴리스는 쿠버네티스 클러스터에서 구성된 모든 쿠버네티스 오브젝트를 관리하는데 사용된다.
helm에서 릴리스는 고유한 이름으로 식별되며, 각 릴리스는 특정 버전의 차트와 연관된다.
릴리스는 업그레이드, 롤백, 삭제 등의 작업을 수행할 수 있다.

 

 


Hands-on: helm으로 Jenkins 설치하기

 

젠킨스란?

젠킨스(Jenkins)는 지속적 통합(CI) 서버로, 소프트웨어 개발 프로세스에서 개발자들이 작성한 코드를 지속적으로 통합하여 빌드, 테스트, 배포등의 과정을 자동화한다. 이를 통해 개발자들은 더욱 짧은 주기로 안정적인 소프트웨어를 제공할 수 있다.
대표적인 오픈소스 지속적 통합 도구이며, 구성이 간단하고 사용이 쉬운 것이 특징이다.

 

젠킨스의 공식 홈페이지를 참고하여 설치를 진행해보자.

 

 


helm 설치

$ 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
brew install helm

위의 명령어들을 차례대로 입력해주면 된다.

 


 

helm이 설치되었다면 다음과 같이 젠킨스 저장소를 추가해주자.

 

$ helm repo add jenkinsci https://charts.jenkins.io
$ helm repo update

 

 

젠킨스 저장소의 helm차트는 다음 명령으로 확인할 수 있다.

$ helm search repo jenkinsci

 

 

레포이름을 jenkinsci로 해줬어서

$ helm install jk jenkins/jenkins

Error: INSTALLATION FAILED: repo jenkins not found라는 에러를 만났다.

 

helm install jk jenkinsci/jenkins

jenkinsci로 변경 후 다음과 같이 확인할 수 있었다.

NAME: jk
LAST DEPLOYED: Thu Feb 16 10:17:55 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. 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
2. 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

3. Login with the password from step 1 and the username: admin
4. Configure security realm and authorization strategy
5. 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

For more information on running Jenkins on Kubernetes, visit:
https://cloud.google.com/solutions/jenkins-on-container-engine

For more information about Jenkins Configuration as Code, visit:
https://jenkins.io/projects/jcasc/


NOTE: Consider using a custom image with pre-installed plugins

 

 

notes에 적힌 내용대로 따라해봅시다

 

아래 명령어를 입력해서 암호를 얻을 수 있습니다.

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

 

 

 

 

포트 포워딩을 통해 서비스를 노출시키고, http://localhost:8080으로 접속합니다.

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

 

 

 

그럼 아래와 같이 로그인화면을 만날 수 있습니다!

 

아이디와 패스워드를 입력해서 로그인 성공!

 

 

 

 

kubectl get all

kubectl get all 명령어로 jenkins차트를 확인해봅시다

 

% kubectl get all
NAME               READY   STATUS    RESTARTS   AGE
pod/jk-jenkins-0   2/2     Running   0          12m

NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
service/jk-jenkins         ClusterIP   10.99.46.78      <none>        8080/TCP    12m
service/jk-jenkins-agent   ClusterIP   10.111.221.105   <none>        50000/TCP   12m

NAME                          READY   AGE
statefulset.apps/jk-jenkins   1/1     12m

 

kubectl get pv,pvc 명령을 통해 pv,pvc도 확인할 수 있다.

kubectl get pv,pvc

NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS   REASON   AGE
persistentvolume/pvc-361b3029-c3b4-4e04-a916-4a8b293159fd   8Gi        RWO            Delete           Bound    default/jk-jenkins   standard                154m

NAME                               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/jk-jenkins   Bound    pvc-361b3029-c3b4-4e04-a916-4a8b293159fd   8Gi        RWO            standard       154m

 

 

helm으로 배포된 jenkins chart를 삭제
$ helm uninstall <RELEASE_NAME>

Jenkins pod와 service를 삭제
$ kubectl delete pod <JENKINS_POD_NAME>
$ kubectl delete service <JENKINS_SERVICE_NAME>

 

 

젠킨스 프로세스 강제 종료

$ ps -ef | grep jenkins
$ kill -9 PID

 

 


https://helm.sh/

 

Helm

Helm - The Kubernetes Package Manager.

helm.sh

https://www.jenkins.io/doc/book/installing/kubernetes/#install-jenkins-with-helm-v3

 

Kubernetes

When you host Jenkins on Kubernetes for production workloads, you need to consider setting up a highly available persistent volume, to avoid data loss during pod or node deletion. A pod or node deletion could happen anytime in Kubernetes environments. It c

www.jenkins.io

https://helm.sh/docs/intro/install/

 

Installing Helm

Learn how to install and get running with Helm.

helm.sh