ApplicationSet 사용
ApplicationSet 사용
ApplicationSet으로 템플릿에서 여러 Application을 생성해 단일 리소스 정의로 여러 클러스터에 배포하는 방법을 설명합니다.
출처: 문서
본문
ApplicationSet은 템플릿에서 여러 Application을 생성하므로, 단일 리소스 정의로 여러 클러스터, 환경, 네임스페이스에 같은 애플리케이션을 배포할 수 있습니다.
사전 요구 사항
- Argo CD 캐퍼빌리티가 생성된 EKS 클러스터
- 리포지토리 접근 구성됨(리포지토리 접근 구성 참고)
- 클러스터와 통신하도록 구성된
kubectl
참고
ApplicationSet에는 여러 대상 클러스터가 필요하지 않습니다. 클러스터 제너레이터가 아닌 다른 제너레이터(list, git 또는 matrix 제너레이터 같은)를 사용해 원격 클러스터 없이 애플리케이션을 배포할 수 있습니다.
ApplicationSet 작동 방식
ApplicationSet은 제너레이터로 매개변수를 생성한 다음, 그 매개변수를 Application 템플릿에 적용합니다. 생성된 각 매개변수 집합이 Application 하나를 만듭니다.
EKS 배포의 일반적인 제너레이터:
- List 제너레이터 - 각 환경에 대한 클러스터와 매개변수를 명시적으로 정의
- Cluster 제너레이터 - 등록된 모든 클러스터에 자동으로 배포
- Git 제너레이터 - 리포지토리 구조에서 Application 생성
- Matrix 제너레이터 - 다차원 배포를 위해 제너레이터 결합
- Merge 제너레이터 - 여러 제너레이터의 매개변수 병합
완전한 제너레이터 레퍼런스는 ApplicationSet Documentation을 참고하세요.
List 제너레이터
명시적 구성으로 여러 클러스터에 배포합니다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook-all-clusters
namespace: argocd
spec:
generators:
- list:
elements:
- environment: dev
replicas: "2"
- environment: staging
replicas: "3"
- environment: prod
replicas: "5"
template:
metadata:
name: 'guestbook-{{environment}}'
spec:
project: default
source:
repoURL: https://github.com/example/guestbook
targetRevision: HEAD
path: 'overlays/{{environment}}'
destination:
name: '{{environment}}-cluster'
namespace: guestbook
syncPolicy:
automated:
prune: true
selfHeal: true
참고
가독성을 위해
destination.name에 클러스터 이름을 사용하세요. 필요하면destination.server필드도 EKS 클러스터 ARN에서 작동합니다.
이렇게 하면 guestbook-dev, guestbook-staging, guestbook-prod 세 개의 Application이 만들어집니다.
Cluster 제너레이터
등록된 모든 클러스터에 자동으로 배포합니다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: cluster-addons
namespace: argocd
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-addons'
spec:
project: default
source:
repoURL: https://github.com/example/cluster-addons
targetRevision: HEAD
path: addons
destination:
server: '{{server}}'
namespace: kube-system
syncPolicy:
automated:
prune: true
selfHeal: true
이렇게 하면 등록된 각 클러스터에 대해 Application이 자동 생성됩니다.
클러스터 필터링:
특정 클러스터를 포함하려면 matchLabels를, 클러스터를 제외하려면 matchExpressions를 사용하세요.
spec:
generators:
- clusters:
selector:
matchLabels:
environment: production
matchExpressions:
- key: skip-appset
operator: DoesNotExist
Git 제너레이터
Git 제너레이터는 리포지토리 구조를 기반으로 Application을 만듭니다.
- Directory 제너레이터 - 각 디렉터리를 별도 Application으로 배포(마이크로서비스에 유용)
- File 제너레이터 - 매개변수 파일에서 Application 생성(멀티 테넌트 배포에 유용)
예시: 마이크로서비스 배포
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: microservices
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/example/microservices
revision: HEAD
directories:
- path: services/*
template:
metadata:
name: '{{path.basename}}'
spec:
project: default
source:
repoURL: https://github.com/example/microservices
targetRevision: HEAD
path: '{{path}}'
destination:
name: my-cluster
namespace: '{{path.basename}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
Git 제너레이터와 파일 기반 구성에 대한 자세한 내용은 Argo CD 문서의 Git Generator를 참고하세요.
Matrix 제너레이터
여러 제너레이터를 결합해 다차원(환경 × 클러스터)에 걸쳐 배포합니다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: multi-env-multi-cluster
namespace: argocd
spec:
generators:
- matrix:
generators:
- list:
elements:
- environment: dev
- environment: staging
- environment: prod
- clusters:
selector:
matchLabels:
region: us-west-2
template:
metadata:
name: 'app-{{environment}}-{{name}}'
spec:
project: default
source:
repoURL: https://github.com/example/app
targetRevision: HEAD
path: 'overlays/{{environment}}'
destination:
name: '{{name}}'
namespace: 'app-{{environment}}'
제너레이터 결합에 대한 자세한 내용은 Argo CD 문서의 Matrix Generator를 참고하세요.
멀티 리전 배포
여러 리전의 클러스터에 배포합니다.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: global-app
namespace: argocd
spec:
generators:
- list:
elements:
- clusterName: prod-us-west
region: us-west-2
- clusterName: prod-us-east
region: us-east-1
- clusterName: prod-eu-west
region: eu-west-1
template:
metadata:
name: 'app-{{region}}'
spec:
project: default
source:
repoURL: https://github.com/example/app
targetRevision: HEAD
path: kubernetes
helm:
parameters:
- name: region
value: '{{region}}'
destination:
name: '{{clusterName}}'
namespace: app
syncPolicy:
automated:
prune: true
selfHeal: true
ApplicationSet 관리
ApplicationSet과 생성된 Application 보기:
kubectl get applicationsets -n argocd
kubectl get applications -n argocd -l argocd.argoproj.io/application-set-name=<name>
ApplicationSet 업데이트:
ApplicationSet 스펙을 수정하고 다시 적용합니다. Argo CD가 생성된 모든 Application을 자동으로 업데이트합니다.
kubectl apply -f applicationset.yaml
ApplicationSet 삭제:
kubectl delete applicationset <name> -n argocd
경고
ApplicationSet을 삭제하면 생성된 모든 Application이 삭제됩니다. 해당 Application에
prune: true가 있으면 그 리소스도 대상 클러스터에서 삭제됩니다.
ApplicationSet 삭제 시 배포된 리소스를 보존하려면 ApplicationSet 스펙에 .syncPolicy.preserveResourcesOnDeletion을 true로 설정하세요. 자세한 내용은 Argo CD 문서의 Application Pruning & Resource Deletion을 참고하세요.
중요
Argo CD의 ApplicationSets 기능에는 ApplicationSet을 사용하기 전에 알고 있어야 할 보안 고려 사항이 있습니다. 자세한 내용은 Argo CD 문서의 ApplicationSet Security를 참고하세요.
추가 리소스
- Argo CD Projects 작업 - Projects로 ApplicationSet 구성
- Application 생성 - Application 구성 이해
- ApplicationSet Documentation - 완전한 제너레이터 레퍼런스와 패턴
- Generator Reference - 상세 제너레이터 스펙