실습
Introduction
Helm이 설치되어 있는지 확인
helm version
Helm이 설치되저 있지 않을 경우 Helm 설치
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
Helm 명령어 목록 확인 - https://helm.sh/docs/helm/helm/
Helm 명령어를 통해서 Artifact Hub에 등록된 차트중에서 ArgoCD 차트 검색
helm search hub argocd
Artifact Hub 사이트에서 ArgoCD 차트 검색 - https://artifacthub.io/
Google을 통해서 ArgoCD Helm 차트 검색 - https://www.google.com/search?q=argocd+helm+chart
ArgoCD 차트가 저장되어져 있는 리포지토리 추가
helm repo add argo https://argoproj.github.io/argo-helm
리포지토리 목록 확인
helm repo list
위에서 추가한 리포지토리에서 제공하는 차트 목록 확인
helm search repo argo
Helm 리포지토리 정보가 저장된 파일 확인
{ ls ~/.config/helm/ cat ~/.config/helm/repositories.yaml }
위에서 추가한 리포지토리에서 제공하는 차트 정보가 저장된 파일 확인
{ cat ~/.cache/helm/repository/argo-index.yaml ls ~/.cache/helm/repository }
리포지토리 삭제
helm repo remove argo
리포지토리 및 차트 정보가 저장된 파일이 같이 삭제 되었는지 확인
{ ll ~/.config/helm/ cat ~/.config/helm/repositories.yaml ll ~/.cache/helm/repository }
ArgoCD 차트가 저장되어져 있는 리포지토리 추가
helm repo add argoo https://argoproj.github.io/argo-helm
리포지토리 목록 확인
helm repo list
위에서 추가한 리포지토리에서 제공하는 차트 목록 확인
helm search repo argoo
리포지토리 및 차트 정보가 저장된 파일을 강제로 삭제
{ rm ~/.config/helm/* rm ~/.cache/helm/repository/* }
리포지토리 목록 확인
helm repo list
ArgoCD 차트 설치 방법 확인 - https://artifacthub.io/packages/helm/argo/argo-cd?modal=install
ArgoCD 차트를 설치할 Namespace 생성
kubectl create ns argocd
ArgoCD 차트 설치
{ helm repo add argo https://argoproj.github.io/argo-helm helm install argo-cd argo/argo-cd --namespace argocd }
설치된 Helm 차트(release) 목록 확인
helm list
모든 네임스페이스에 생성된 Helm 배포 목록 확인
helm list --all-namespaces
생성된 객체 확인
kubectl get all -n argocd
ArgoCD 차트에 포함된 템플릿 확인 - https://artifacthub.io/packages/helm/argo/argo-cd?modal=template
차트 설치(업그레이드)에 사용된 변수 확인
helm get values argo-cd -n argocd
차트에 적용된 기본 변수 확인 - https://artifacthub.io/packages/helm/argo/argo-cd?modal=values
helm show values argo/argo-cd
ArgoCD 서버의 서비스 유형을 LoadBalacer로 변경해서 차트 업그레이드
helm upgrade argo-cd argo/argo-cd --set server.service.type=LoadBalancer -n argocd
ArgoCD 서버의 서비스 유형이 변경되었는지 확인
kubectl get svc -n argocd
차트 설치(업그레이드) 할때 덮어쓰기된 변수 확인
helm get values argo-cd -n argocd
차트 설치(업그레이드)에 사용된 변수 확인
helm get values argo-cd --all -n argocd | less
차트 설치(업그레이드)에 사용된 쿠버네티스 객체 명세 파일(Manifest) 확인
helm get manifest argo-cd -n argocd
Helm 차트 삭제
helm uninstall argo-cd -n argocd
쿠버네티스 객체도 같이 삭제되었는지 확인
kubectl get all -n argocd
Argocd 설치에 사용한 리포지토리의 인덱스 파일 확인
cat ~/.cache/helm/repository/argo-index.yaml
Argocd 설치에 사용한 리포지토리의 인덱스 파일 다운로드
wget https://argoproj.github.io/argo-helm/index.yaml
위의 2개 파일 비교
diff ~/.cache/helm/repository/argo-index.yaml index.yaml -s
위에서 다운받은 인덱스 파일을 통해서 최신 버전의 ArgoCD 차트 정보 확인
yq '.entries.argo-cd[0]' index.yaml
최신 버전의 ArgoCD 차트를 다운로드 받을수 있는 경로 확인
yq '.entries.argo-cd[0].urls[0]' index.yaml
해당 차트가 로컬 캐시에 다운로드 되어져 있는지 확인
ls ~/.cache/helm/repository
차트 다운로드
wget $(yq '.entries.argo-cd[0].urls[0]' index.yaml) -O argocd.tgz
차트 설치
helm install argo-cd ./argocd.tgz -n argocd
설치된 Helm 차트(release) 목록 확인
helm list -n argocd
Helm 차트가 설치된 네임스페이스에 있는 Secret 객체 확인
kubectl get secret -n argocd
helm.sh/release.v1
유형의 Secret 내용 확인kubectl describe secrets sh.helm.release.v1.argo-cd.v1 -n argocd
Data에 저장된 내용 확인
kubectl get secrets sh.helm.release.v1.argo-cd.v1 \ -o jsonpath='{.data.release}' -n argocd \ | base64 -d | base64 -d | gzip -d | jq
helm.sh/release.v1
유형의 Secret 삭제kubectl delete secrets sh.helm.release.v1.argo-cd.v1 -n argocd
설치된 Helm 차트(release) 목록 확인
helm list -n argocd
생성된 Pod 목록 확인
kubectl get pod -n argocd
Helm 차트 재설치
helm install argo-cd ./argocd.tgz -n argocd
Pod들이 새로 생성되었는지 확인
kubectl get pod -n argocd
Helm 배포 삭제
helm uninstall argo-cd -n argocd
리소스가 삭제 되었는지 확인
kubectl get all -n argocd
설치된 Helm 차트(release) 목록 확인
helm list -A
Namespace 삭제
kubectl delete ns argocd
Helm charts - Part 1
Helm 차트를 저장할 디렉토리를 생성하고 해당 디렉토리로 이동
mkdir my-app && cd my-app
Chart.yaml 파일 생성
cat > Chart.yaml <<EOF name: my-app version: 1.0.0 EOF
차트에 포함될 YAML 파일을 저장할 디렉토리 생성
mkdir templates
ConfigMap을 명시할 YAML 파일 생성
cat > templates/configmap.yaml <<EOF apiVersion: v1 kind: ConfigMap metadata: name: my-app labels: app: my-app data: index.html: | hello my-app EOF
ServiceAccount를 명시할 YAML 파일 생성
cat > templates/serviceaccount.yaml <<EOF apiVersion: v1 kind: ServiceAccount metadata: name: my-app labels: app: my-app EOF
Deployment를 명시할 YAML 파일 생성
cat > templates/deployment.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: my-app labels: app: my-app spec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: serviceAccountName: my-app containers: - name: my-app image: nginx ports: - containerPort: 80 volumeMounts: - name: html mountPath: /usr/share/nginx/html volumes: - name: html configMap: name: my-app EOF
Service를 명시할 YAML 파일 생성
cat > templates/service.yaml <<EOF apiVersion: v1 kind: Service metadata: name: my-app labels: app: my-app spec: ports: - port: 80 targetPort: 80 selector: app: my-app EOF
templates 디렉토리 안에 생성된 파일 확인
ls templates
차트 배포
helm install my-app .
배포된 차트 목록 확인
helm ls
생성된 리소스 확인
kubectl get svc,deploy,cm,sa -l app=my-app
Helm을 통해서 생성된 리소스에 부여된 Label 확인
kubectl get svc,deploy,cm,sa -l app=my-app --show-labels
데모 애플리케이션이 정상적으로 배포되었는지 확인
kubectl run nginx --image=nginx -it --rm --restart=Never -- curl my-app
deployment.yaml 파일에 명시된 replicas 확인
cat templates/deployment.yaml | grep replicas
replicas의 값을 3으로 변경
sed -i 's/replicas: .*/replicas: 3/' templates/deployment.yaml
replicas의 값이 변경되었는지 확인
cat templates/deployment.yaml | grep replicas
위에서 수정한 변경분을 반영
helm upgrade my-app .
생성된 Deployment의 Replica 갯수 확인
kubectl get deploy -l app=my-app
Pod 갯수 확인
kubectl get pod -l app=my-app
배포된 차트의 기록 확인
helm history my-app
이번 버전으로 롤백
helm rollback my-app 1
생성된 Deployment의 Replica 갯수 확인
kubectl get deploy -l app=my-app
Pod 갯수 확인
kubectl get pod -l app=my-app
배포된 차트의 기록 확인
helm history my-app
Helm 배포 삭제
helm uninstall my-app
리소스가 삭제 되었는지 확인
kubectl get svc,deploy,cm,sa -l app=my-app
배포된 차트 목록 확인
helm ls
차트에 주입할 파라미터들의 기본값들을 명시할 values.yaml 파일 생성
cat > values.yaml <<EOF # Default values for my-app. # This is a YAML-formatted file. # Declare variables to be passed into your templates. EOF
Deployment에 명시할 replica 값을 values.yaml 파일에 변수로 지정
cat >> values.yaml <<EOF replicaCount: 2 EOF
Deployment를 명시한 YAML 파일 수정
cat > templates/deployment.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: my-app labels: app: my-app spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: serviceAccountName: my-app containers: - name: my-app image: nginx ports: - containerPort: 80 volumeMounts: - name: html mountPath: /usr/share/nginx/html volumes: - name: html configMap: name: my-app EOF
차트 배포
helm install my-app .
생성된 Deployment의 Replica 갯수 확인
kubectl get deploy -l app=my-app
replicaCount를 Helm 명령어에 파라미터로 명시하고 차트 업그레이드
helm upgrade my-app . --set replicaCount=5
Deployment의 Replica 갯수 확인
kubectl get deploy -l app=my-app
values_dev.yaml 이라는 이름으로 파일을 생성하고 변수 명시
cat >> values_dev.yaml <<EOF replicaCount: 1 EOF
위에서 생성한 파일을 Helm 명령어에 파라미터로 명시하고 차트 업그레이드
helm upgrade my-app . -f values_dev.yaml
Deployment의 Replica 갯수 확인
kubectl get deploy -l app=my-app
차트 삭제
{ helm uninstall my-app cd ~/environment }
Helm charts - Part 2
Helm 차트 생성
{ helm create frontend cd frontend }
생성된 차트 내용 확인
{ cat Chart.yaml cat values.yaml ls templates }
NGINX 애플리케이션 배포에 사용할 변수 생성
cat >> nginx_dev.yaml <<EOF image: repository: nginx replicaCount: 2 EOF
Apache 애플리케이션 배포에 사용할 변수 파일 생성
cat >> httpd_dev.yaml <<EOF image: repository: httpd tag: latest EOF
위에서 생성한 Helm 차트와 변수 파일을 통해서 NGINX 애플리케이션 배포
helm install nginx . -f nginx_dev.yaml
위에서 생성한 Helm 릴리즈를 통해서 생성된 객체 확인
kubectl get all \ -l='app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=nginx'
위에서 생성한 Helm 차트와 변수 파일을 통해서 Apache 애플리케이션 배포
helm install httpd . -f httpd_dev.yaml
위에서 생성한 Helm 릴리즈를 통해서 생성된 객체 확인
kubectl get all \ -l='app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=httpd'
배포된 애플리케이션 목록 확인
helm ls
애플리케이션 삭제
helm uninstall nginx httpd
위에서 생성한 Helm 차트를 GitHub 리포지토리에 업로드 - https://github.com/youngwjung/helm-chart-frontend
ArgoCD 설치
{ kubectl create ns argocd helm install argo-cd argo/argo-cd -n argocd \ --set server.service.type=LoadBalancer \ --set configs.params."server\.insecure"=true }
ArgoCD 어드민 비밀번호 확인
kubectl -n argocd get secret argocd-initial-admin-secret \ -o jsonpath="{.data.password}" | base64 -d
ArgoCD 접속 URL 확인 후 ArgoCD에 로그인
kubectl -n argocd get svc argo-cd-argocd-server \ -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}{"\n"}'
ArgoCD 애플리케이션 생성 - NGINX
cat <<EOF | kubectl apply -f - apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: nginx namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io spec: project: default source: repoURL: https://github.com/youngwjung/helm-chart-frontend.git targetRevision: HEAD path: . helm: valueFiles: - nginx_dev.yaml destination: name: in-cluster namespace: default syncPolicy: automated: prune: true EOF
ArgoCD에서 애플리케이션이 정상 생성되었는지 확인
ArgoCD 애플리케이션 생성 - Apache
cat <<EOF | kubectl apply -f - apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: httpd namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io spec: project: default source: repoURL: https://github.com/youngwjung/helm-chart-frontend.git targetRevision: HEAD path: . helm: valueFiles: - httpd_dev.yaml destination: name: in-cluster namespace: default syncPolicy: automated: prune: true EOF
ArgoCD에서 애플리케이션이 정상 생성되었는지 확인
templates 디렉토리 하위에 있는 deployment.yaml 파일을 아래와 같이 수정하고 커밋
apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "frontend.fullname" . }}-edited labels: {{- include "frontend.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: {{- include "frontend.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: {{- include "frontend.labels" . | nindent 8 }} {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "frontend.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: {{ .Values.service.port }} protocol: TCP livenessProbe: {{- toYaml .Values.livenessProbe | nindent 12 }} readinessProbe: {{- toYaml .Values.readinessProbe | nindent 12 }} resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.volumeMounts }} volumeMounts: {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.volumes }} volumes: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }}
수정 사항이 각각의 애플리케이션에 반영 되었는지 확인
ArgoCD에 생성한 애플리케이션 삭제
kubectl delete application nginx httpd -n argocd
애플리케이션 변수 파일을 저장할 디렉토리를 생성하고 변수 파일을 이동
{ mkdir ~/environment/frontend-values mv nginx_dev.yaml httpd_dev.yaml ~/environment/frontend-values }
GitHub 리포지토리를 생성하고 변수 파일들을 업로드 - https://github.com/youngwjung/helm-chart-frontend-values
Chart.yaml을 열고 버전을 1.0.0으로 수정
Helm 차트 패키지 생성
helm package .
Helm 차트를 저장할 ECR 리포지토리 생성
aws ecr create-repository --repository-name helm-charts/frontend
ECR 리포지토리 로그인
aws ecr get-login-password --region ap-northeast-2 | helm registry login \ --username AWS \ --password-stdin 491818659652.dkr.ecr.ap-northeast-2.amazonaws.com
Helm 차트 업로드
helm push frontend-1.0.0.tgz \ oci://491818659652.dkr.ecr.ap-northeast-2.amazonaws.com/helm-charts
차트가 정상적으로 업로드 되었는지 확인
aws ecr describe-images \ --repository-name helm-charts/frontend \ --region ap-northeast-2
ArgoCD에 ECR 리포지토리 자격증명 등록
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Secret metadata: name: ecr-helm namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: helm url: 491818659652.dkr.ecr.ap-northeast-2.amazonaws.com name: ecr-helm username: AWS password: $(aws ecr get-login-password --region ap-northeast-2) EOF
ArgoCD 애플리케이션 생성 - NGINX
cat <<EOF | kubectl apply -f - apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: nginx namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io spec: project: default sources: - repoURL: 491818659652.dkr.ecr.ap-northeast-2.amazonaws.com chart: helm-charts/frontend targetRevision: 1.0.0 helm: valueFiles: - \$values/nginx_dev.yaml - repoURL: https://github.com/youngwjung/helm-chart-frontend-values.git targetRevision: HEAD ref: values destination: name: in-cluster namespace: default syncPolicy: automated: prune: true EOF
ArgoCD에서 애플리케이션이 정상 생성되었는지 확인
ArgoCD 애플리케이션 생성 - Apache
cat <<EOF | kubectl apply -f - apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: httpd namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io spec: project: default sources: - repoURL: 491818659652.dkr.ecr.ap-northeast-2.amazonaws.com chart: helm-charts/frontend targetRevision: 1.0.0 helm: valueFiles: - \$values/httpd_dev.yaml - repoURL: https://github.com/youngwjung/helm-chart-frontend-values.git targetRevision: HEAD ref: values destination: name: in-cluster namespace: default syncPolicy: automated: prune: true EOF
ArgoCD에서 애플리케이션이 정상 생성되었는지 확인
templates 디렉토리 하위에 있는 deployment.yaml 파일을 아래와 같이 수정
apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "frontend.fullname" . }}-edited labels: {{- include "frontend.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: {{- include "frontend.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: {{- include "frontend.labels" . | nindent 8 }} {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "frontend.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http containerPort: {{ .Values.service.port }} protocol: TCP livenessProbe: {{- toYaml .Values.livenessProbe | nindent 12 }} readinessProbe: {{- toYaml .Values.readinessProbe | nindent 12 }} resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.volumeMounts }} volumeMounts: {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.volumes }} volumes: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }}
Chart.yaml을 열고 버전을 1.0.1으로 수정
Helm 차트 패키지 생성
{ rm *.tgz helm package . }
Helm 차트 업로드
helm push frontend-1.0.1.tgz \ oci://491818659652.dkr.ecr.ap-northeast-2.amazonaws.com/helm-charts
차트가 정상적으로 업로드 되었는지 확인
aws ecr describe-images \ --repository-name helm-charts/frontend \ --region ap-northeast-2
ArgoCD UI에서 Apache 애플리케이션의 차트 버전을 1.0.1로 수정
애플리케이션이 정상 업그레이드 되는지 확인
리소스 삭제
{ kubectl delete application nginx httpd -n argocd helm uninstall argo-cd -n argocd kubectl delete ns argocd aws ecr delete-repository --repository-name helm-charts/frontend --force }
Last updated