Overview
이번 글에서는 ArgoCD의 핵심 확장 기능인 ApplicationSet에 대해 알아본다.
ApplicationSet은 여러 환경이나 클러스터에 대해 반복적인 Application 정의를 자동화하고, GitOps 방식으로 다양한 배포 구성을 선언적으로 처리할 수 있게 도와준다.
특히, 템플릿과 생성기(Generators)를 조합하여 동적으로 여러 애플리케이션을 생성할 수 있다는 점에서, 운영 효율성과 유지 보수성을 크게 향상시킨다.
글에서는 ApplicationSet의 구성 요소인 Templating, 다양한 Generator 종류(List, Cluster, Git, Matrix), 동적 업데이트 기능과 DRY 원칙의 실현 방식에 대해 상세히 설명하고,
EKS, GKE, On-premise 환경별 실습 예시도 함께 정리하여 실제 활용까지 이어질 수 있도록 구성하였다.
📅 관련 글
2023.05.16 - [IaC/CI CD Tool] - ArgoCD란?
2023.08.09 - [IaC/CI CD Tool] - ArgoCD 설치 AWS & GCP
2023.10.02 - [IaC/CI CD Tool] - ArgoCD ApplicationSet이란? (작성 방법)
2023.10.08 - [Container Orchestration/Kubernetes] - 2. Kustomize + ArgoCD ApplicationSet
2024.02.02 - [IaC/CI CD Tool] - Argo Workflow란?
2024.04.09 - [IaC/CI CD Tool] - ArgoCD SSO 구성 가이드(GCP Oauth)
2025.02.19 - [IaC/CI CD Tool] - ArgoCD SSO 구성 가이드(Gitlab)
ArgoCD ApplicationSet이란?
ApplicationSet은 다수의 환경이나 클러스터에 Application을 쉽게 배포할 수 있도록 한다.
각 환경에 대해 Application을 수동으로 정의하여 템플릿으로 만들 수 있다.
핵심 사항 및 주요 기능
- 1. Templating
- 2. Generators
- 3. Dynamic Update
- 4. DRY Principle
1. Templating
ArgoCD Application Template을 정의할 수 있고 ApplicationSet은 특정 파라미터를 변경하여 여러 개의 Application을 생성할 수 있다. 예를 들어 스테이징 및 프로덕션 환경이 있을 수 있으며 둘 모두에 대한 응용 프로그램을 생성하는 단일 템플릿이 있을 수 있다.
2. Generators
ApplicationSet은 템플릿에 대입되는 파라미터를 생성하기 위해 생성기를 사용한다.
List Generator
List Generator를 사용하여 여러 클러스터 또는 네임스페이스에 동일한 어플리케이션을 배포할 수 있다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook-appset
spec:
generators:
- list:
items:
- cluster: staging
url: https://staging-cluster-api-server
- cluster: production
url: https://production-cluster-api-server
template:
metadata:
name: 'guestbook-{{cluster}}'
spec:
source:
repoURL: 'https://github.com/my-org/guestbook.git'
targetRevision: HEAD
destination:
server: '{{url}}'
namespace: 'guestbook'
Cluster Generator
Cluster Generator는 ArgoCD에서 관리하는 클러스터를 대상으로 어플리케이션을 생성한다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: cluster-generator-example
spec:
generators:
- clusters:
selector:
matchLabels:
argocd.argoproj.io/secret-type: cluster
template:
metadata:
name: '{{name}}-app'
spec:
project: default
source:
repoURL: 'https://github.com/my-org/my-repo.git'
targetRevision: HEAD
destination:
server: '{{server}}'
namespace: 'default'
Git Generator
Git Generator를 사용하면 Git 레포지토리의 특정 경로에 따라 어플리케이션을 동적으로 생성할 수 있다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook-appset
spec:
generators:
- git:
repoURL: 'https://github.com/my-org/app-repo.git'
directories:
- 'clusters/*/apps/'
template:
metadata:
name: '{{path.basename}}'
spec:
source:
repoURL: 'https://github.com/my-org/app-repo.git'
path: '{{path}}'
destination:
server: 'https://kubernetes.default.svc'
namespace: 'default'
Matrix Generator
Matrix Generator는 기존의 여러 Generator 출력을 사용하여 그들 간의 Cartesian Product(곱집합)을 생성하는데 사용된다.
따라서 여러 파라미터 조합에 대한 어플리케이션을 생성하는 것이 가능하다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: matrix-example
spec:
generators:
- matrix:
generators:
- list:
items:
- cluster: cluster1
url: https://cluster1-api-server
- cluster: cluster2
url: https://cluster2-api-server
- list:
items:
- app: app1
repo: https://github.com/my-org/app1.git
- app: app2
repo: https://github.com/my-org/app2.git
template:
metadata:
name: '{{app}}-on-{{cluster}}'
spec:
source:
repoURL: '{{repo}}'
targetRevision: HEAD
destination:
server: '{{url}}'
namespace: 'default'
PullRequest Generator
PullRequest Generator는 GitHub 또는 GitLab의 오픈된 Pull Request 정보를 기반으로 각 PR 브랜치를 미리보기 환경(Preview Environment)로 배포할 수 있도록 Application을 동적으로 생성한다.
CI 파이프라인과 함께 사용하면 특정 PR을 테스트 환경에 자동 배포하는 구조를 만들 수 있다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: pr-generator
spec:
generators:
- pullRequest:
github:
owner: somaz94
repo: demo-app
tokenRef:
secretName: github-token
key: token
requeueAfterSeconds: 30
template:
metadata:
name: 'preview-{{number}}'
spec:
source:
repoURL: 'https://github.com/somaz94/demo-app.git'
targetRevision: '{{head_sha}}'
path: 'app'
destination:
server: 'https://kubernetes.default.svc'
namespace: 'pr-{{number}}'
3. Dynamic Update(동적 업데이트)
Generator의 소스가 변경되면(예를 들어, Git Generator에서 사용하는 Git 저장소에 새로운 디렉토리가 추가되면)
ApplicationSet은 자동으로 새로운 ArgoCD 어플리케이션을 생성하거나 변경된 내용을 기반으로 기존의 어플리케이션을 업데이트 또는 삭제할 수 있다.
4. DRY Principle(DRY 원칙)
ApplicationSet을 사용하면 DRY(Don't Repeat Yourself) 원칙을 따른다. 어플리케이션의 공통 구조를 한 번 정의한 다음 차이점을 매개 변수화한다.
- Maintainability(유지 보수성)
- Readability(가독성)
- Resuability(재사용성)
- Bug Reduction or Decrease in Bugs(버그감소)
DRY는 "Don't Repeat Yourself" 의 약자로, 소프트웨어 개발에서 중복을 최소화하자는 원칙이다.
중복된 코드, 기능 또는 로직이 프로젝트 내에서 여러 번 반복되는 것을 피하도록 강조하며 이를 통해 유지 보수성을 향상시키고 버그의 가능성을 줄일 수 있다.
ArgoCD ApplicationSet 활용
아래의 링크에 ArgoCD ApplicationSet 예시를 정의해 놓았다.
EKS / GCP / Onpremise 3개의 예시로 나누어서 설명해보려고 한다.
EKS용 ArgoCD ApplicationSet
aws-applicationset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: aws-appicationset
spec:
generators:
- matrix:
generators:
- list:
elements:
- cluster: somaz-eks
url: https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.sk1.ap-northeast-2.eks.amazonaws.com # EKS url
values:
environment: dev1
project: somaz-aws
- cluster: somaz-eks
url: https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.sk1.ap-northeast-2.eks.amazonaws.com # EKS url
values:
environment: dev2
project: somaz-aws
- git:
repoURL: git@github.com:somaz94/helm-chart-template.git
revision: HEAD
directories:
- path: aws/eks_fargate_use_efs/* # path
template:
metadata:
name: '{{values.environment}}-{{values.project}}-{{path.basename}}'
spec:
project: '{{cluster}}'
source:
repoURL: git@github.com:somaz94/helm-chart-template.git
targetRevision: HEAD
path: '{{path}}'
helm:
version: v3
valueFiles:
- '{{path.basename}}.values.yaml'
destination:
server: '{{url}}'
namespace: '{{values.environment}}-{{path.basename}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
GKE용 ArgoCD ApplicationSet
gcp-applicationset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: gcp-appicationset
spec:
generators:
- matrix:
generators:
- list:
elements:
- cluster: somaz-gke
url: https://1.1.1.1 # ClusterIP
values:
environment: dev1
project: somaz-gcp
- git:
repoURL: git@github.com:somaz94/helm-chart-template.git
revision: HEAD
directories:
- path: gcp/gke_use_nfs_server/* # Path
template:
metadata:
name: '{{values.environment}}-{{values.project}}-{{path.basename}}'
spec:
project: '{{cluster}}'
source:
repoURL: git@github.com:somaz94/helm-chart-template.git
targetRevision: HEAD
path: '{{path}}'
helm:
version: v3
valueFiles:
- '{{path.basename}}.values.yaml'
destination:
server: '{{url}}'
namespace: '{{values.namespace}}-{{path.basename}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
Onpremise Cluster용 ArgoCD ApplicationSet
onpremise-applicationset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: onpremise-appicationset
spec:
generators:
- matrix:
generators:
- list:
elements:
- cluster: master-node.somaz.link # your cluster name
url: https://xx.xx.xxx.xx:6443 # your cluster url
values:
project: somaz-onpremise
environment: dev1
- git:
repoURL: git@github.com:somaz94/helm-chart-template.git # your source repo
revision: HEAD
directories:
- path: onpremise/ke-use-nfs-server/*
template:
metadata:
name: '{{values.environment}}-{{values.project}}-{{path.basename}}'
spec:
project: '{{values.project}}'
source:
repoURL: git@github.com:somaz94/helm-chart-template.git
targetRevision: HEAD
path: '{{path}}'
helm:
version: v3
valueFiles:
- '{{path.basename}}.values.yaml'
destination:
server: '{{url}}'
namespace: '{{values.project}}-{{path.basename}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
syncPolicy 주요 옵션 설명
- `automated`: ArgoCD가 Application을 자동으로 동기화한다.
- `prune`: 삭제된 리소스도 제거
- `selfHeal`: 수동 변경된 리소스를 원래대로 복원
- `syncOptions`:
- `CreateNamespace=true`: 지정된 네임스페이스가 없을 경우 자동 생성
- `ApplyOutOfSyncOnly=true`: OutOfSync 상태인 리소스만 적용 (전체 리소스 재적용 방지)
운영 시 주의사항 및 Best Practice
- Generator Overlap 주의: 여러 Generator가 중복 Application을 생성하지 않도록 Generator 조합 시 명확한 기준 설정 필요
- 네임스페이스 관리: Matrix나 Git Generator 사용 시 네임스페이스 충돌 방지용으로 네이밍 규칙 설정 권장
- 분리된 프로젝트 구조: 환경(environment)과 클러스터(cluster)를 Git 폴더 구조로 잘 분리하여 관리하면 유지보수가 쉬움
- Helm Values 파일 버전 관리: `{{path.basename}}.values.yaml` 패턴을 쓸 경우, Helm chart 구조가 명확해야 실수가 줄어든다
마무리
ArgoCD ApplicationSet은 GitOps를 넘어, 다중 클러스터 운영과 마이크로서비스 배포 전략을 단순화할 수 있는 강력한 도구다.
특히, 환경에 따라 반복되는 설정을 일관성 있게 관리하고자 할 때 매우 유용하며,
List, Git, Cluster, Matrix Generator 등 다양한 방식으로 자동화 범위를 넓힐 수 있다는 점은 실무에서 큰 장점으로 작용한다.
또한 실습을 통해 EKS, GKE, 온프레미스 환경에 맞춘 실전 YAML 구성까지 익힐 수 있었기 때문에,
ApplicationSet 도입을 고려하는 팀이라면 이 글을 통해 초기 구성을 빠르게 시작할 수 있을 것이다.
향후에는 ApplicationSet과 Kustomize, Helm, 또는 ApplicationSet + ApplicationSet 조합 같은 고급 패턴도 정리해볼 예정이니 참고하면 도움이 될 것이다.
ArgoCD를 활용한 진정한 GitOps 자동화를 실현하고 싶다면, ApplicationSet은 반드시 익혀야 할 기능이다.
Reference
https://argo-cd.readthedocs.io/en/stable/user-guide/application-set/
https://github.com/somaz94/helm-chart-template/tree/main/argocd-applicationset
'IaC > CI CD Tool' 카테고리의 다른 글
4. Github Action (With Matrix Strategy) (2) | 2024.03.12 |
---|---|
Argo Workflow란? (2) | 2024.02.09 |
5. GitLab ArgoCD 연동 (0) | 2023.08.10 |
ArgoCD 설치 AWS & GCP (0) | 2023.08.09 |
4. GitLab 버전 업그레이드 (0) | 2023.08.08 |