-
[Helm] Helm (2)kubernetes 2025. 1. 20. 15:54
Helm
Helm 차트 생성
실습
[Helm Chart 구성 전 작업]
# Helm chart 생성 전, 구성 yaml 파일 생성
# Create helm chart : mynginx mkdir manifests kubectl create deployment webserver --image nginx:1.25.2 --port 80 -o yaml > manifests/deployment.yaml kubectl expose deployment webserver --port 80 --target-port 80 --type NodePort -o yaml > manifests/service.yaml tree manifests/ kubectl delete -f deployments.yaml kubectl delete -f service.yaml
# deployment.yaml 파일 수정
root@master:~/manifests# vi deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: webserver namespace: default spec: replicas: 1 selector: matchLabels: app: webserver template: metadata: labels: app: webserver spec: containers: - image: nginx:1.25.2 imagePullPolicy: IfNotPresent name: nginx ports: - containerPort: 80
그냥 냅둬도 되는데 필요없는 spec들 지워보자,,
# service.yaml 파일 수정
root@master:~/manifests# vi service.yaml apiVersion: v1 kind: Service metadata: name: webserver namespace: default spec: ports: - port: 80 protocol: TCP targetPort: 80 selector: app: webserver type: NodePort
# helm chart 생성
root@master:~# helm create mynginx Creating mynginx
# helm chart 구조 확인
root@master:~# tree mynginx/ mynginx/ ├── Chart.yaml ├── charts ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── hpa.yaml │ ├── ingress.yaml │ ├── service.yaml │ ├── serviceaccount.yaml │ └── tests │ └── test-connection.yaml └── values.yaml 4 directories, 10 files
불필요 파일 삭제 후 다시 확인해보자
root@master:~# rm mynginx/templates/*.yaml mynginx/templates/{_helpers.tpl,NOTES.txt} root@master:~# rm -rf mynginx/templates/tests/
root@master:~# tree mynginx/ mynginx/ ├── Chart.yaml ├── charts ├── templates └── values.yaml 3 directories, 2 files
아까 manifests 디렉터리에 만들어 놓은 yaml 파일을 해당 nginx chart에 복사하자
root@master:~# cd manifests root@master:~/manifests# ls deployment.yaml service.yaml
root@master:~# cp manifests/* mynginx/templates/ root@master:~# tree mynginx/ mynginx/ ├── Chart.yaml ├── charts ├── templates │ ├── deployment.yaml │ └── service.yaml └── values.yaml 3 directories, 4 files
# Chart를 테스트 실행하여 문법 오류 유무 확인
# chart를 TEST 실행하여 오류 유무를 확인 # helm lint PATH [flags] helm lint mynginx/
# helm chart 실행
root@master:~# helm install webserver ./mynginx NAME: webserver LAST DEPLOYED: Mon Jan 20 06:53:10 2025 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None
# 확인
root@master:~# kubectl get all NAME READY STATUS RESTARTS AGE pod/webserver-6fdb4fc7d-bkrcf 1/1 Running 0 49s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12d service/webserver NodePort 10.96.55.139 <none> 80:30438/TCP 49s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/webserver 1/1 1 1 49s NAME DESIRED CURRENT READY AGE replicaset.apps/webserver-6fdb4fc7d 1 1 1 49s
root@master:~# curl localhost:30438
service의 port로 접근해서, nginx 화면이 잘 나오면 성공
# 삭제
root@master:~# helm uninstall webserver release "webserver" uninstalled
실습2
# mynginx chart에 변수(values.yaml) 설정
root@master:~# cat > mynginx/values.yaml replicaCount: 1 image: repository: nginx tag: 1.25.2 pullPolicy: IfNotPresent pullSecret: service: type: NodePort
# deployment.yaml 파일 수정
root@master:~/mynginx/templates# vi deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: "deploy-{{ .Release.Name }}" namespace: default spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: app: "{{ .Chart.Name }}" template: metadata: labels: app: "{{ .Chart.Name }}" spec: containers: - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: "{{ .Values.image.pullPolicy }}" name: "{{ .Chart.Name }}" ports: - containerPort: 80
변수값을 통해 할당이 되게 끔 파일 수정
# service.yaml 파일 수정
root@master:~/mynginx/templates# vi service.yaml apiVersion: v1 kind: Service metadata: name: "svc-{{ .Release.Name }}" namespace: default spec: type: "{{ .Values.service.type }}" ports: - port: 80 protocol: TCP targetPort: 80 selector: app: "{{ .Chart.Name }}"
해당 파일도 동일
# tree 구조로 확인
root@master:~# tree mynginx/ mynginx/ ├── Chart.yaml ├── charts ├── templates │ ├── deployment.yaml │ └── service.yaml └── values.yaml 3 directories, 4 files
# helm chart 실행
root@master:~# helm install webserver ./mynginx/ NAME: webserver LAST DEPLOYED: Mon Jan 20 07:32:23 2025 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None
# 확인
root@master:~# kubectl get all NAME READY STATUS RESTARTS AGE pod/deploy-webserver-75ddfdc77c-659l2 1/1 Running 0 2m10s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12d service/svc-webserver NodePort 10.104.9.36 <none> 80:31048/TCP 2m10s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/deploy-webserver 1/1 1 1 2m10s NAME DESIRED CURRENT READY AGE replicaset.apps/deploy-webserver-75ddfdc77c 1 1 1 2m10s
# Helm chart rolling update
root@master:~# helm upgrade --set image.repository=httpd --set image.tag=2.2.34-alpine webserver mynginx Release "webserver" has been upgraded. Happy Helming! NAME: webserver LAST DEPLOYED: Mon Jan 20 07:39:35 2025 NAMESPACE: default STATUS: deployed REVISION: 2 TEST SUITE: None
# 확인
root@master:~# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VE RSION webserver default 2 2025-01-20 07:39:35.467990862 +0000 UTC deployed mynginx-0.1.0 1.16.0
# Helm chart rolling back
root@master:~# helm rollback webserver 1 Rollback was a success! Happy Helming!
revision 1로 rollback
# 확인
root@master:~# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VE RSION webserver default 3 2025-01-20 07:43:50.593053996 +0000 UTC deployed mynginx-0.1.0 1.16.0
# 삭제
root@master:~# helm uninstall webserver release "webserver" uninstalled
helm chart package(파일) 만들기
# helm chart package 생성
root@master:~# helm package mynginx/ Successfully packaged chart and saved it to: /root/mynginx-0.1.0.tgz
# 확인
root@master:~# ls mynginx-0.1.0.tgz
mynginx-0.1.0.tgw 파일이 만들어졌다.
* 0.1.0 : 차트 버전정보
# 차트 버전 정보 수정 후 helm package 생성
root@master:~# vi mynginx/Chart.yaml apiVersion: v2 name: mynginx description: A Helm chart for running nginx web server type: application version: 0.2.0 appVersion: "1.16.0"
Chart.yaml 파일의 버전 정보를 0.2.0로 업데이트했다.
root@master:~# helm package mynginx/ Successfully packaged chart and saved it to: /root/mynginx-0.2.0.tgz
# 확인
root@master:~# helm package mynginx/ Successfully packaged chart and saved it to: /root/mynginx-0.2.0.tgz root@master:~# ls mynginx-0.2.0.tgz
[참고 영상]
https://www.youtube.com/watch?v=DEUMYnR5wv4&list=PLApuRlvrZKohLYdvfX-UEFYTE7kfnnY36&index=14
'kubernetes' 카테고리의 다른 글
[따배쿠] Helm (0) 2025.01.20 [따배쿠] Custom Resource (0) 2025.01.20 [따배쿠] Kubernetes Autoscaling - 운영 (0) 2025.01.19 [따배쿠] 로그 관리 (1) 2025.01.08 [따배쿠] 인증과 권한 관리 - 권한관리편 (0) 2024.12.29