DevOps, Infra

[ArgoCD] helm chart 배포하는 방법

seulseul 2023. 11. 12. 04:37

개요

ArgoCD 에서 helm차트를 release방법을 설명합니다.

ArgoCD Application 은 application 파일을 kubectl 명령어로 생성합니다.

1. helm repo 사용

Application CRD

# application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nginx
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io  
  
spec:
  project: default

  source:
    repoURL: https://charts.bitnami.com/bitnami
    chart: nginx    
    targetRevision: "15.4.2"

  destination:
    namespace: nginx
    server: "https://kubernetes.default.svc"

  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

 

Argocd에서는 helm repo 에서 helm chart 를 참조할 수 있습니다.

본문에서는 bitnami repo 의 nginx chart를 사용하겠습니다.

 

source 설정

  • repoURL  : helm repository URL 지정
  • chart  :  chart name 지정
  • targetRevision  :  chart 버전 지정

 

 

Custom values 추가

# application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nginx
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io  
  
spec:
  project: default

  source:
    repoURL: https://charts.bitnami.com/bitnami
    chart: nginx    
    targetRevision: "15.4.2"
    helm:
      values: |-
        nameOverride: "nginx"
          
  destination:
    namespace: nginx
    server: "https://kubernetes.default.svc"

  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

 

  • application yaml에 spec.source.helm.values 를 사용하면 커스텀 values 를 사용할 수 있습니다.
  • values.yaml의 규격을 그대로 사용하면 됩니다.

 

 

 

위의 정보는 Artifact Hub에서 install을 클릭하여 확인할 수 있습니다.

 

 

순서대로 helm repo url , chart name, chart version입니다.

위의 정보를 넣으시면 됩니다.

 

kubectl apply -f application.yaml

 

kubectl apply 명령어를 사용하여 argocd application 배포하면 됩니다.

 

 

 

ArgoCD 대시보드에서 nginx 가 생성된 것을 확인할 수 있습니다.

 

 

2. values.yaml 커스텀을 위해 Github Repo 사용 

두 번째 방법은 helm chart 를 개인 GitHub Repo  가져와서 사용하는 방법입니다.

Application CRD

# application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nginx
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io  
  
spec:
  project: default

  source:
    path: charts/nginx
    repoURL: https://github.com/jei0486/demo-argocd.git
    targetRevision: HEAD

  destination:
    namespace: nginx
    server: "https://kubernetes.default.svc"

  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

 

 

GitHub

GitHub 의 charts 폴더 하위에  nginx helm chart 가 위치하므로 이를 path로 지정합니다.

깃헙 소스코드는 아래 주소에서 확인할 수 있습니다.

 

https://github.com/jei0486/demo-argocd

 

GitHub - jei0486/demo-argocd: argocd app

argocd app. Contribute to jei0486/demo-argocd development by creating an account on GitHub.

github.com

 

 

 

 

nginx namespace에 리소스가 생성된 것을 확인할 수 있습니다.

 

ArgoCD 대시보드에서 생성된 application 을 확인 할 수 있습니다.

 

 

 

 

3. Multiple sources for applications

 

argocd 2.3 버전 기준으로는 helm chart와 value file을 따로 두지 못하기 때문에 원본 차트를 clone 하여 custom values.yaml 을 작성하는데, 이는 오픈소스가 버전업 될 때마다 chart 를 git clone 작업을 해야 하는 번거로움이 생깁니다.

해당 이슈: https://github.com/argoproj/argo-cd/issues/2789

 

Argocd Release Version 2.6에서부터 Multiple Sources를 지원합니다.

원본 helm chart 와  custom values.yaml 파일을 각각 다른 저장소에서 사용할 수 있습니다.

참고: https://github.com/argoproj/argo-cd/pull/10432

 

Application CRD

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nginx
  namespace: argocd
spec:
  project: default

  destination:
    server: https://kubernetes.default.svc
    namespace: nginx
  
  sources:
    - repoURL: https://github.com/jei0486/demo-argocd.git  # path is missing so no manifests are generated
      targetRevision: HEAD
      ref: myRepo                                          # repo is available via symlink "myRepo"
    - repoURL: https://github.com/bitnami/charts.git
      targetRevision: HEAD
      path: bitnami/nginx                                  # path "bitnami/nginx" is used to generate manifests
      helm:
        valueFiles:
          - $myRepo/values/nginx-values.yaml               # "values/nginx-values.yaml" is located in source with reference name $myRepo

  syncPolicy:
    automated:
      prune: true
      selfHeal: true

 

GitHub : https://github.com/jei0486/demo-argocd/blob/main/multi-repo-application.yaml


주의 사항

ArgoCD 에서 배포한 helm 차트는 helm 배포로 등록되지 않습니다.

helm list -n nginx 명령어를 치면 argocd로 배포한 nginx chart 가 나타나지 않습니다. 

 

이는 argocd 가 helm chart를 다음과 같이 배포하기 때문입니다.

helm template . <options> | kubectl apply -f -​

 

참고: https://argo-cd.readthedocs.io/en/stable/faq/#after-deploying-my-helm-application-with-argo-cd-i-cannot-see-it-with-helm-ls-and-other-helm-commands

 

그렇기 때문에 argocd로 helm을 배포한다면 helm 명령어를 사용할 수 없습니다.

argocd 로 deploy, rollback을 해야 합니다.

 


 

argocd로 배포한 helm chart 

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: '1'
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"nginx","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"nginx","app.kubernetes.io/version":"1.25.3","argocd.argoproj.io/instance":"nginx","helm.sh/chart":"nginx-15.4.2"},"name":"nginx","namespace":"nginx"},"spec":{"replicas":1,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app.kubernetes.io/instance":"nginx","app.kubernetes.io/name":"nginx"}},"strategy":{"rollingUpdate":{},"type":"RollingUpdate"},"template":{"metadata":{"annotations":null,"labels":{"app.kubernetes.io/instance":"nginx","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"nginx","app.kubernetes.io/version":"1.25.3","helm.sh/chart":"nginx-15.4.2"}},"spec":{"affinity":{"nodeAffinity":null,"podAffinity":null,"podAntiAffinity":{"preferredDuringSchedulingIgnoredDuringExecution":[{"podAffinityTerm":{"labelSelector":{"matchLabels":{"app.kubernetes.io/instance":"nginx","app.kubernetes.io/name":"nginx"}},"topologyKey":"kubernetes.io/hostname"},"weight":1}]}},"automountServiceAccountToken":false,"containers":[{"env":[{"name":"BITNAMI_DEBUG","value":"false"},{"name":"NGINX_HTTP_PORT_NUMBER","value":"8080"}],"envFrom":null,"image":"docker.io/bitnami/nginx:1.25.3-debian-11-r1","imagePullPolicy":"IfNotPresent","livenessProbe":{"failureThreshold":6,"initialDelaySeconds":30,"periodSeconds":10,"successThreshold":1,"tcpSocket":{"port":"http"},"timeoutSeconds":5},"name":"nginx","ports":[{"containerPort":8080,"name":"http"}],"readinessProbe":{"failureThreshold":3,"initialDelaySeconds":5,"periodSeconds":5,"successThreshold":1,"tcpSocket":{"port":"http"},"timeoutSeconds":3},"resources":{"limits":{},"requests":{}},"securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"readOnlyRootFilesystem":false,"runAsNonRoot":true,"runAsUser":1001,"seccompProfile":{"type":"RuntimeDefault"}},"volumeMounts":null}],"hostIPC":false,"hostNetwork":false,"initContainers":null,"securityContext":{"fsGroup":1001,"sysctls":[]},"serviceAccountName":"default","shareProcessNamespace":false,"volumes":null}}}}
  creationTimestamp: '2023-11-11T19:25:19Z'
  generation: 1
  labels:
    app.kubernetes.io/instance: nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: nginx
    app.kubernetes.io/version: 1.25.3
    argocd.argoproj.io/instance: nginx
    helm.sh/chart: nginx-15.4.2
  name: nginx
  namespace: nginx

 

 

 

helm 명령어로 설치

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    meta.helm.sh/release-name: nginx
    meta.helm.sh/release-namespace: nginx
  creationTimestamp: "2023-11-11T19:35:04Z"
  generation: 1
  labels:
    app.kubernetes.io/instance: nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: nginx
    app.kubernetes.io/version: 1.25.3
    helm.sh/chart: nginx-15.4.2
  name: nginx
  namespace: nginx

 

  • 어노테이션에 meta.helm.sh 가 붙어있습니다.

 

 

 

참고

https://argo-cd.readthedocs.io/en/stable/user-guide/helm/

https://cloud.redhat.com/blog/continuous-delivery-with-helm-and-argo-cd