| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 31 | 
- kubernetes
- Jenkins
- AWS
- k8s
- codepresso
- ci/cd
- NoSQL
- docker
- springboot
- 아키텍처
- 코드프레소
- Elastic Load Balancing
- ELB
- REPLICATION
- Typesript
- Auto Scaling Group
- Redis
- ASG
- TypeScript
- Today
- Total
Study Note
쿠버네티스 helm - [Kubernetes, k8s] 본문
helm
helm은 apt, yum, pip와 비슷하게 플랫폼의 패키지를 관리하는 쿠버네티스 패키지 매니저입니다. helm 패키지는 YAML 형식으로 구성되어 있는 chart를 사용합니다.
helm chart 구조
쿠버네티스틑 helm을 이용하여 프로세스(Pod), 네트워크(Service), 저장소(PersistentVolume) 등 어플리케이션에 필요한 모든 자원들을 외부에서 가져올 수 있습니다.

- values.yaml : 사용자가 원하는 값을 설정하는 파일입니다.
- templates/ 디렉토리 : 설치할 리소스 파일들이 존재하는 디렉토리입니다. 디렉토리 안에는 Deployment, Service 같은 쿠버네티스 리소스가 YAML 파일 형태로 저장되어 있으며 각 파일의 설정값은 비워져 있고(placeholder) values.yaml 설정값들로 채워집니다.
helm 설치
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -s -- --version v3.2.2chart 생성
다음 명령어를 통해서 chart를 생성할 수 있습니다.
helm create <CHART_NAME>helm create mychart
#Creating mychart
ls mychart
#Chart.yaml  charts  templates  values.yaml- Chart.yaml : chart 이름, 버전 정보와 같은 chart의 전반적인 정보를 담고 있습니다.
- charts : chart 속에 또 다른 여러 chart들을 넣을 수 있습니다. [기본적으로 비어있습니다.]
- templates/ : chart의 뼈대가 되는 쿠버테니스 리소스가 들어있는 디렉토리입니다.
- values.yaml : 사용자가 지정한 설정값을 가진 YAML 파일 입니다.
서비스 포트를 수정해서 실행해 보겠습니다.
ls mychart/templates
#NOTES.txt  _helpers.tpl  deployment.yaml  hpa.yaml  ingress.yaml  service.yaml  serviceaccount.yaml  tests#cat ./mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ include "mychart.fullname" . }}
  labels:
    {{- include "mychart.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "mychart.selectorLabels" . | nindent 4 }}values.yaml 파일의 service.type과 service.port를 다음과 같이 변경합니다.
#cat ./mychart/values.yaml
replicaCount: 1
image:
  repository: nginx
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart version.
  tag: ""
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
...
service:
  type: LoadBalancer # 기존 ClusterIP
  port: 8080 # 기존 80
...chart 설치
chart는 다음과 같은 명령어 형태를 통해 설치가 가능합니다.
helm은 다른 패키지 매니저와 다르게 모든 라이브러리 종속성이 컨테이너 안에서 해결되기 때문에 helm에서 실제 사용할 프로세스만 생성됩니다.
helm install <CHART_NAME> <CHART_PATH>helm install foo ./mychart
#NAME: foo
#LAST DEPLOYED: Sun Aug  8 02:11:03 2021
#NAMESPACE: default
#STATUS: deployed
#REVISION: 1
#NOTES:
#1. Get the application URL by running these commands:
#     NOTE: It may take a few minutes for the LoadBalancer IP to be available.
#           You can watch the status of by running 'kubectl get --namespace default svc -w foo-mychart'
#  export SERVICE_IP=$(kubectl get svc --namespace default foo-mychart --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
#  echo http://$SERVICE_IP:8080kubectl get svc
#NAME          TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
#kubernetes    ClusterIP      10.43.0.1      <none>        443/TCP          16d
#foo-mychart   LoadBalancer   10.43.216.54   172.31.1.47   8080:32443/TCP   46schart 리시트 조회
다음 명령어로 통해 helm chart 리스트를 조회할 수 있습니다. 이때 -n(namespace) 옵션을 이용하여 조회할 수도 있습니다.
helm list
helm list -n <NAMESPACE>chart 랜더링
실제 설치가 되는것이 아닌 values.yaml 파일과 templates 디렉토리 안의 파일들이 합쳐진 YAML 결과를 확인할 때 사용하는 방법입니다. helm은 이 방법을 rendering한다고 표현하며 kubectl의 --dry-run 옵션과 유사합니다.
helm template <CHART_PATH>template 결과물을 보면 이전의 리소스 YAML과 크게 다르지 않습니다.
helm template foo ./mychart > foo-output.yaml
cat foo-output.yaml
#apiVersion: v1
#kind: ServiceAccount
#metadata:
#  name: foo-mychart
#  labels:
#    helm.sh/chart: mychart-0.1.0
#    app.kubernetes.io/name: mychart
#    app.kubernetes.io/instance: foo
#    app.kubernetes.io/version: "1.16.0"
#    app.kubernetes.io/managed-by: Helm
...
#spec:
#  containers:
#    - name: wget
#      image: busybox
#      command: ['wget']
#      args: ['foo-mychart:8080']
...chart 업그레이드
이미 설치한 chart에 대해 values.yaml 값을 수정하여 업데이트할 수 있습니다.
helm upgrade <CHART_NAME> <CHART_PATH>service 타입을 변경해서 업데이트를 하는 방법입니다.
sudo vim ./mychart/values.yaml
...
#service:
#  type: NodePort # 기존 LoadBalancer
#  port: 8080
...helm upgrade foo ./mychart
#Release "foo" has been upgraded. Happy Helming!
#NAME: foo
#LAST DEPLOYED: Sun Aug  8 02:27:35 2021
#NAMESPACE: default
#STATUS: deployed
#REVISION: 2
#NOTES:
#1. Get the application URL by running these commands:
#  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services foo-mychart)
#  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
#  echo http://$NODE_IP:$NODE_PORTkubectl get svc
#NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
#kubernetes    ClusterIP   10.43.0.1      <none>        443/TCP          16d
#foo-mychart   NodePort    10.43.216.54   <none>        8080:32443/TCP   17mchart를 업그레이드 하면 다음과 같이 REVISION이 놀라갑니다.
helm list
#NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
#foo     default         2               2021-08-08 02:27:35.574862779 +0000 UTC deployed        mychart-0.1.0   1.16.0chart 배포상태 확인
chart 배포상태는 다음 명령어를 사용해서 확인할 수 있습니다.
helm status <CHART_NAME>helm status foo
#NAME: foo
#LAST DEPLOYED: Sun Aug  8 02:27:35 2021
#NAMESPACE: default
#STATUS: deployed
#REVISION: 2
#NOTES:
#1. Get the application URL by running these commands:
#  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services foo-mychart)
#  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
#  echo http://$NODE_IP:$NODE_PORTchart 삭제
다음 명령어를 사용해서 helm chart를 삭제할 수 있습니다.
helm delete <CHART_NAME>helm delete foo
#release "foo" uninstalled
helm list
#NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION원격 Repository
helm은 chart 원격 저장소인 Repository가 존재합니다. Repository는 chart를 한 곳에 묶어서 보관해놓은 저장소 입니다.
Helm 공식 저장소
Helm Repository 문서
Artifact Hub
Find, install and publish Kubernetes packages
artifacthub.io
차트 저장소 가이드
헬름 차트 저장소를 만들고 작업하는 방법
helm.sh
Repository추가
다음 명령어를 통해 Repository를 추가할 수 있습니다.
helm repo add <NAME> <URL>helm repo add stable https://charts.helm.sh/stable
#"stable" has been added to your repositoriesRepository업데이트
추가한 Repository의 인덱스 정보를 최신으로 업데이트합니다.
helm repo updatehelm repo update
#Hang tight while we grab the latest from your chart repositories...
#...Successfully got an update from the "stable" chart repository
#Update Complete. ⎈ Happy Helming!⎈Repository 조회
helm repo listhelm repo list
#NAME    URL
#stable  https://charts.helm.sh/stableRepository내 Chart 조회
helm search repo <REPOSITORY_NAME> <FLAGS>helm search repo stable
#NAME                                    CHART VERSION   APP VERSION             DESCRIPTION
#stable/acs-engine-autoscaler            2.2.2           2.1.1                   DEPRECATED Scales worker nodes within agent pools
#stable/aerospike                        0.3.5           v4.5.0.5                DEPRECATED A Helm chart for Aerospike in Kubern...
#stable/airflow                          7.13.3          1.10.12                 DEPRECATED - please use: https://github.com/air...
#stable/ambassador                       5.3.2           0.86.1                  DEPRECATED A Helm chart for Datawire Ambassador
#stable/anchore-engine                   1.7.0           0.7.3                   Anchore container analysis and policy evaluatio...
#stable/apm-server                       2.1.7           7.0.0                   DEPRECATED The server receives data from the El...
#stable/ark                              4.2.2           0.10.2                  DEPRECATED A Helm chart for ark외부 Chart 설치 (WordPress)
chart install
원격 Repository인 stable Repository의 WordPress chart를 설치해보겠습니다.
helm install wp stable/wordpress \
--version 9.0.3 \
--set service.port=8080
--namespace default- --version : chart의 버전을 지정합니다. Chart.yaml의 version 정보를 참조합니다.
- --set : values.yaml 값을 동적으로 설정할 수 있습니다.
- --namespace : chart가 설치될 네이스페이스를 지정합니다.
chart fetch
Repository의 chart를 원격에서 바로 설치가 가능하지만 로컬 디렉토리로 다운로드해서 사용할 수 있습니다.
helm fetch --untar stable/wordpress --version 9.0.3- --untar 옵션 : 폴더에 압축이 풀어진 상태로 저장합니다.
