

 **이 페이지 개선에 도움 주기** 

이 사용자 가이드에 기여하려면 모든 페이지의 오른쪽 창에 있는 **GitHub에서 이 페이지 편집** 링크를 선택합니다.

# ApplicationSet 사용
<a name="argocd-applicationsets"></a>

ApplicationSet는 템플릿에서 여러 애플리케이션을 생성하므로 단일 리소스 정의를 사용하여 여러 클러스터, 환경 또는 네임스페이스에서 동일한 애플리케이션을 배포할 수 있습니다.

## 사전 조건
<a name="_prerequisites"></a>
+ Argo CD 기능이 생성된 EKS 클러스터
+ 구성된 리포지토리 액세스([리포지토리 액세스 구성](argocd-configure-repositories.md) 참조)
+  클러스터와 통신하도록 구성된 `kubectl`

**참고**  
ApplicationSets에는 여러 대상 클러스터가 필요하지 않습니다. 클러스터 생성기(예: 목록, git 또는 매트릭스 생성기) 이외의 생성기를 사용하여 원격 클러스터 없이 애플리케이션을 배포할 수 있습니다.

## ApplicationSet 작동 방식
<a name="_how_applicationsets_work"></a>

ApplicationSet는 생성기를 사용하여 파라미터를 생성한 다음 해당 파라미터를 애플리케이션 템플릿에 적용합니다. 생성된 각 파라미터 세트는 하나의 애플리케이션을 생성합니다.

EKS 배포를 위한 일반 생성기:
+  **목록 생성기** - 각 환경에 대한 클러스터 및 파라미터 명시적으로 정의
+  **클러스터 생성기** - 등록된 모든 클러스터에 자동으로 배포
+  **Git 생성기** - 리포지토리 구조에서 애플리케이션 생성
+  **매트릭스 생성기** - 다차원 배포를 위해 생성기 결합
+  **생성기 병합** - 여러 생성기의 파라미터 병합

전체 생성기 참조는 [ApplicationSet 설명서](https://argo-cd.readthedocs.io/en/stable/user-guide/application-set/)를 참조하세요.

## 목록 생성기
<a name="_list_generator"></a>

명시적 구성으로 여러 클러스터에 배포합니다.

```
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`와 같은 3개의 애플리케이션이 생성됩니다.

## 클러스터 생성기
<a name="_cluster_generator"></a>

등록된 모든 클러스터에 자동으로 배포합니다.

```
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
```

그러면 등록된 각 클러스터에 대한 애플리케이션이 자동으로 생성됩니다.

 **클러스터 필터링**:

`matchLabels`를 사용하여 특정 클러스터를 포함하거나 `matchExpressions`를 사용하여 클러스터를 제외합니다.

```
spec:
  generators:
  - clusters:
      selector:
        matchLabels:
          environment: production
        matchExpressions:
        - key: skip-appset
          operator: DoesNotExist
```

## Git 생성기
<a name="_git_generators"></a>

Git 생성기는 리포지토리 구조에 기반해 애플리케이션을 생성합니다.
+  **디렉터리 생성기** - 각 디렉터리를 별도의 애플리케이션으로 배포(마이크로서비스에 유용)
+  **파일 생성기** - 파라미터 파일에서 애플리케이션 생성(다중 테넌트 배포에 유용)

 **예제: 마이크로서비스 배포** 

```
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](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Git/)를 참조하세요.

## 매트릭스 생성기
<a name="_matrix_generator"></a>

여러 생성기를 결합하여 여러 차원(환경 × 클러스터)에 배포합니다.

```
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](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/)를 참조하세요.

## 다중 리전 배포
<a name="_multi_region_deployment"></a>

여러 리전의 클러스터에 배포합니다.

```
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 관리
<a name="_manage_applicationsets"></a>

 **ApplicationSet 및 생성된 애플리케이션 보기**:

```
kubectl get applicationsets -n argocd
kubectl get applications -n argocd -l argocd.argoproj.io/application-set-name=<applicationset-name>
```

 **ApplicationSet 업데이트**

ApplicationSet 사양을 수정하고 다시 적용합니다. Argo CD는 생성된 모든 애플리케이션을 자동으로 업데이트합니다.

```
kubectl apply -f applicationset.yaml
```

 **ApplicationSet 삭제**:

```
kubectl delete applicationset <name> -n argocd
```

**주의**  
ApplicationSet를 삭제하면 생성된 모든 애플리케이션이 삭제됩니다. 해당 애플리케이션에 `prune: true`가 있는 경우 해당 리소스는 대상 클러스터에서도 삭제됩니다.  
ApplicationSet를 삭제할 때 배포된 리소스를 보존하려면 ApplicationSet 사양에서 `.syncPolicy.preserveResourcesOnDeletion`을 `true`로 설정합니다. 자세한 내용은 Argo CD 설명서의 [Application Pruning & Resource Deletion](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Application-Deletion/)을 참조하세요.

**중요**  
Argo CD의 ApplicationSets 기능에는 ApplicationSets를 사용하기 전에 알아야 하는 보안 고려 사항이 있습니다. 자세한 내용은 Argo CD 설명서의 [ApplicationSet Security](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Security/)를 참조하세요.

## 추가 리소스
<a name="_additional_resources"></a>
+  [Argo CD 프로젝트 작업](argocd-projects.md) - 프로젝트로 ApplicationSets 구성
+  [애플리케이션 생성](argocd-create-application.md) - 애플리케이션 구성 이해
+  [ApplicationSet 설명서](https://argo-cd.readthedocs.io/en/stable/user-guide/application-set/) - 전체 생성기 참조 및 패턴
+  [생성기 참조](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators/) - 자세한 생성기 사양