使用 ApplicationSets - Amazon EKS

協助改進此頁面

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

若要為本使用者指南貢獻內容,請點選每個頁面右側面板中的在 GitHub 上編輯此頁面連結。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 ApplicationSets

ApplicationSets 從 範本產生多個應用程式,可讓您使用單一資源定義,在多個叢集、環境或命名空間之間部署相同的應用程式。

先決條件

  • 建立 Argo CD 功能的 EKS 叢集

  • 已註冊多個目標叢集 (請參閱 註冊目標叢集)

  • 已設定儲存庫存取 (請參閱 設定儲存庫存取)

  • kubectl 設定為與您的叢集通訊

ApplicationSets 的運作方式

ApplicationSets 使用產生器產生參數,然後將這些參數套用至應用程式範本。每組產生的參數都會建立一個應用程式。

EKS 部署的常見產生器:

  • 列出產生器 - 明確定義每個環境的叢集和參數

  • 叢集產生器 - 自動部署到所有已註冊的叢集

  • Git 產生器 - 從儲存庫結構產生應用程式

  • 矩陣產生器 - 合併多維部署的產生器

如需完整的產生器參考,請參閱 ApplicationSet 文件

列出產生器

使用明確組態部署到多個叢集:

apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: guestbook-all-clusters namespace: argocd spec: generators: - list: elements: - cluster: arn:aws:eks:us-west-2:111122223333:cluster/dev-cluster environment: dev replicas: "2" - cluster: arn:aws:eks:us-west-2:111122223333:cluster/staging-cluster environment: staging replicas: "3" - cluster: arn:aws:eks:us-west-2:111122223333:cluster/prod-cluster 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: server: '{{cluster}}' namespace: guestbook syncPolicy: automated: prune: true selfHeal: true
注意

將已註冊的 EKS 叢集ARNs。 server您也可以搭配 使用叢集名稱,destination.name而非 destination.server

這會建立三個應用程式:guestbook-devguestbook-stagingguestbook-prod

叢集產生器

自動部署到所有已註冊的叢集:

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

這會自動為每個註冊的叢集建立 應用程式。

篩選叢集

spec: generators: - clusters: selector: matchLabels: environment: production

Git 產生器

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: server: arn:aws:eks:us-west-2:111122223333:cluster/my-cluster namespace: '{{path.basename}}' syncPolicy: automated: prune: true selfHeal: true syncOptions: - CreateNamespace=true

如需 Git 產生器和檔案型組態的詳細資訊,請參閱 Argo CD 文件中的 Git 產生器

矩陣產生器

結合多個產生器以跨多個維度部署 (環境 × 叢集):

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: server: '{{server}}' namespace: 'app-{{environment}}'

如需結合產生器的詳細資訊,請參閱 Argo CD 文件中的矩陣產生器

漸進推展

使用不同的同步政策依序部署到環境:

apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: progressive-rollout namespace: argocd spec: generators: - list: elements: - environment: dev autoSync: "true" - environment: staging autoSync: "true" - environment: prod autoSync: "false" template: metadata: name: 'app-{{environment}}' spec: project: default source: repoURL: https://github.com/example/app targetRevision: HEAD path: 'overlays/{{environment}}' destination: server: arn:aws:eks:us-west-2:111122223333:cluster/{{environment}}-cluster namespace: app syncPolicy: automated: prune: true selfHeal: '{{autoSync}}'

自動開發和預備同步,而生產則需要手動核准。

多區域部署

部署到跨多個區域的叢集:

apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: global-app namespace: argocd spec: generators: - list: elements: - cluster: arn:aws:eks:us-west-2:111122223333:cluster/prod-us-west region: us-west-2 - cluster: arn:aws:eks:us-east-1:111122223333:cluster/prod-us-east region: us-east-1 - cluster: arn:aws:eks:eu-west-1:111122223333:cluster/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: server: '{{cluster}}' namespace: app syncPolicy: automated: prune: true selfHeal: true

管理 ApplicationSets

檢視 ApplicationSets 和產生的應用程式

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,其資源也會從目標叢集中刪除。

其他資源