차트 개발 팁과 요령

Install, Upgrade, Uninstall



1. Install 및 Upgrade Tip


Install and Upgrade  for Helm.

1-1) Chart Template 생성

helm create mychart

templates 폴더 안에 불필요한 파일 삭제

rm -rf deployment.yaml  hpa.yaml  ingress.yaml  service.yaml  serviceaccount.yaml  tests

1-2) deployment.yaml 내용 업데이트

vi deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      type: app
  replicas: 1
  template:
    metadata:
      labels:
        type: app
    spec:
      initContainers:
      - name: init-myservice
        image: kubetm/app
        command: ["sh", "-c", "echo 'start'; sleep 30; echo 'done'"]
      containers:
      - name: container
        image: kubetm/app
        envFrom:
        - configMapRef:
            name: test-cm
        volumeMounts:
        - name: volume
          mountPath: /hostpath
      volumes:
      - name : volume
        persistentVolumeClaim:
          claimName: test-pvc

1-3) configmap.yaml 추가

vi configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-cm
data:
  env: prod
  log: Error

1-4) pvc.yaml 추가

vi pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1G
  storageClassName: ""
  selector:
    matchLabels:
      name: test-pv

1-5) pv.yaml 추가

vi pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
  labels:
    name: test-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1G
  hostPath:
    path: /host1
    type: DirectoryOrCreate

1-6) Install, Upgrade 명령

cd ..
helm install mychart . -n nm-1

helm install mychart . -n nm-1 --create-namespace
kubectl get ns nm-1
kubectl get -n nm-1 pods

helm upgrade mychart . -n nm-1 
helm uninstall mychart -n nm-1 

helm upgrade mychart . -n nm-1 --create-namespace --install
helm upgrade mychart . -n nm-1 --create-namespace --install --wait --timeout 10m


2. Pod 자동 재기동 Tip


Pod Auto Deployment for Helm.

2-1) configmap.yaml 수정

vi configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-cm
data:
  env: prod
  log: Info
helm upgrade mychart . -n nm-1 --create-namespace --install
kubectl get -n nm-1 pods
kubectl get -n nm-1 cm -o yaml
kubectl exec -n nm-1 test-7c4fff79cd-4m5st -it env

2-2) deployment.yaml 내용 업데이트

vi deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      type: app
  replicas: 1
  template:
    metadata:
      labels:
        type: app
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
#        rollme: {{ randAlphaNum 5 | quote }}
    spec:
      containers:
      - name: container
      ...
helm upgrade mychart . -n nm-1 --create-namespace --install
kubectl get -n nm-1 pods
kubectl exec -n nm-1 test-7c4fff79cd-4m5st -it env

helm upgrade mychart . -n nm-1 --create-namespace --install
kubectl get -n nm-1 pods
kubectl get -n nm-1 deployment -o yaml


3. 기타 Resource 특성


Etc Resource for Helm.

3-1) pv.yaml 내용 업데이트

vi pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
  labels:
    name: test-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1G
  hostPath:
    path: /host2
    type: DirectoryOrCreate
helm upgrade mychart . -n nm-1 --create-namespace --install
helm uninstall mychart -n nm-1
kubectl get pv
kubectl get pvc -n nm-1
helm upgrade mychart . -n nm-1 --create-namespace --install
kubectl get pv -o yaml

helm list -n nm-1
helm uninstall mychart -n nm-1
helm list -n nm-1
kubectl get ns nm-1
kubectl delete ns nm-1

3-2) Uninstall시 Namespace 확인

helm uninstall mychart -n nm-1


4. Helm 저장소


Helm Deployment Repository for Helm.

4-1) Install 및 Upgrade 실행

helm upgrade mychart . -n nm-1 --create-namespace --install

4-2) Secret 확인

kubectl get -n nm-1 secret -l name=mychart
kubectl get -n nm-1 secret sh.helm.release.v1.mychart.v1 -o yaml

4-3) Helm History 확인

helm history -n nm-1 mychart
helm upgrade mychart . -n nm-1 --create-namespace --install --history-max 2
kubectl get -n nm-1 secret -l name=mychart
helm history -n nm-1 mychart


Referenece


Helm