기존에는 k8s 디렉터리 아래의 YAML 파일을 직접 적용했음.
k8s/
namespace.yaml
pv-pvc.yaml
secret.example.yaml
configmap-nginx.yaml
statefulset-db.yaml
deployment-web.yaml
service-web.yaml
ingress.yaml
kubectl apply -f k8s/
파일이 많아지고 이미지, Namespace, NFS 경로, 포트 등을 수정할 때마다 여러 YAML을 확인해야 해서 Helm Chart로 묶기 시작함.
Helm Chart 구조:
helm/rhymix/
Chart.yaml
values.yaml
templates/
namespace.yaml
pv-pvc.yaml
configmap-nginx.yaml
statefulset-db.yaml
service-db.yaml
deployment-web.yaml
service-web.yaml
ingress.yaml
기존 YAML에 있던 고정값을 values.yaml로 분리함.
namespace:
create: false
name: 3009-yeonghoon-kim
imagePullSecrets:
-
name: gitlab-registry-secret
web:
replicaCount: 1
nginx:
image:
repository: nginx
tag: alpine
pullPolicy: IfNotPresent
php:
image:
repository: registry.yeonghoon.kim/ioniere/3009-yeonghoon.kim/rhymix-php
tag: 8.2-001
pullPolicy: IfNotPresent
service:
port: 80
db:
replicaCount: 1
image:
repository: mariadb
tag: "10.6"
pullPolicy: IfNotPresent
service:
port: 3306
existingSecret: rhymix-db-secret
persistence:
nfsServer: 192.168.200.100
storageClassName: ""
html:
pvName: 3009-rhymix-html-pv
claimName: rhymix-html
size: 20Gi
accessMode: ReadWriteMany
path: /mnt/k8s-nfs/3009-yeonghoon.kim/html
mariadb:
pvName: 3009-rhymix-mariadb-pv
claimName: rhymix-mariadb
size: 10Gi
accessMode: ReadWriteOnce
path: /mnt/k8s-nfs/3009-yeonghoon.kim/mariadb
ingress:
enabled: true
className: nginx
hosts:
- yeonghoon.kim
- www.yeonghoon.kim
Secret 값은 Chart에 넣지 않고 기존 rhymix-db-secret과 gitlab-registry-secret을 이름으로만 참조함.
Chart 확인:
Helm Chart 문법을 확인한다.
helm lint ./helm/rhymix
Kubernetes에 적용될 YAML을 미리 출력한다.
helm template rhymix ./helm/rhymix -n 3009-yeonghoon-kim --set namespace.create=false
기존 리소스는 바로 삭제하지 않고 Helm 관리 메타데이터를 붙여 adoption 방식으로 전환함.
기존 Namespace와 Secret을 유지한 상태로 Helm release를 설치한다.
helm upgrade --install rhymix ./helm/rhymix -n 3009-yeonghoon-kim --set namespace.create=false
Helm release 상태를 확인한다.
helm list -n 3009-yeonghoon-kim
helm status rhymix -n 3009-yeonghoon-kim
Pod, PVC, Service, Ingress 상태를 확인한다.
kubectl get pods,pvc,svc,ingress -n 3009-yeonghoon-kim -o wide
기존 k8s 디렉터리는 비교와 복구용으로 남겨두고 helm/rhymix를 추가함.