建立應用程式 - Amazon EKS

協助改進此頁面

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

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

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

建立應用程式

應用程式代表目標叢集中的部署。每個應用程式都會定義來源 (Git 儲存庫) 和目的地 (叢集和命名空間)。套用時,Argo CD 會將 Git 儲存庫中資訊清單指定的資源建立到叢集中的命名空間。應用程式通常會指定工作負載部署,但可以管理目的地叢集中可用的任何 Kubernetes 資源。

先決條件

建立基本應用程式

定義從 Git 儲存庫部署的應用程式:

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: guestbook namespace: argocd spec: project: default source: repoURL: https://github.com/argoproj/argocd-example-apps targetRevision: HEAD path: guestbook destination: server: arn:aws:eks:us-west-2:111122223333:cluster/my-cluster namespace: default
重要

destination.server 欄位中使用 EKS 叢集 ARN,而不是 Kubernetes API 伺服器 URL。受管功能需要 ARNs才能識別叢集。

套用應用程式:

kubectl apply -f application.yaml

檢視應用程式狀態:

kubectl get application guestbook -n argocd

來源組態

Git 儲存庫

spec: source: repoURL: https://github.com/example/my-app targetRevision: main path: kubernetes/manifests

特定 Git 標籤或遞交

spec: source: targetRevision: v1.2.0 # or commit SHA

Helm Chart

spec: source: repoURL: https://github.com/example/helm-charts targetRevision: main path: charts/my-app helm: valueFiles: - values.yaml parameters: - name: image.tag value: v1.2.0

ECR 的 Helm Chart

spec: source: repoURL: oci://account-id.dkr.ecr.region.amazonaws.com/repository-name targetRevision: chart-version chart: chart-name

如果功能角色具有必要的 ECR 許可,則直接使用儲存庫,不需要儲存庫組態。如需詳細資訊,請參閱 設定儲存庫存取

CodeCommit 的 Git 儲存庫

spec: source: repoURL: https://git-codecommit.region.amazonaws.com/v1/repos/repository-name targetRevision: main path: kubernetes/manifests

如果功能角色具有必要的 CodeCommit 許可,則直接使用儲存庫,不需要儲存庫組態。如需詳細資訊,請參閱 設定儲存庫存取

CodeConnections 中的 Git 儲存庫

spec: source: repoURL: https://codeconnections.region.amazonaws.com/git-http/account-id/region/connection-id/owner/repository.git targetRevision: main path: kubernetes/manifests

儲存庫 URL 格式衍生自 CodeConnections 連線 ARN。如果功能角色具有必要的 CodeConnections 許可,且已設定連線,則會直接使用儲存庫,而且不需要儲存庫組態。如需詳細資訊,請參閱 設定儲存庫存取

Kustomize

spec: source: repoURL: https://github.com/example/kustomize-app targetRevision: main path: overlays/production kustomize: namePrefix: prod-

同步政策

控制 Argo CD 同步應用程式的方式。

手動同步 (預設)

應用程式需要手動核准才能同步:

spec: syncPolicy: {} # No automated sync

手動觸發同步:

kubectl patch application guestbook -n argocd \ --type merge \ --patch '{"operation": {"initiatedBy": {"username": "admin"}, "sync": {}}}'

自動同步

偵測到 Git 變更時,應用程式會自動同步:

spec: syncPolicy: automated: {}

自我修復

自動將手動變更還原至叢集:

spec: syncPolicy: automated: selfHeal: true

啟用後,Argo CD 會還原直接對叢集所做的任何手動變更,確保 Git 仍然是事實來源。

剔除

自動刪除從 Git 移除的資源:

spec: syncPolicy: automated: prune: true
警告

刪除 會從叢集刪除資源。在生產環境中謹慎使用 。

合併自動同步

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

同步選項

其他同步組態:

如果命名空間不存在,請建立命名空間

spec: syncPolicy: syncOptions: - CreateNamespace=true

在套用之前驗證資源

spec: syncPolicy: syncOptions: - Validate=true

僅套用不同步

spec: syncPolicy: syncOptions: - ApplyOutOfSyncOnly=true

進階同步功能

Argo CD 支援複雜部署的進階同步功能:

  • 同步波 – 使用argocd.argoproj.io/sync-wave註釋控制資源建立順序

  • 同步掛鉤 - 使用argocd.argoproj.io/hook註釋同步之前或之後執行任務 (PreSync、PostSync、SyncFail)

  • 資源運作狀態評估 - 自訂應用程式特定資源的運作狀態檢查

如需詳細資訊,請參閱 Argo CD 文件中的同步波和資源勾點

忽略差異

防止 Argo CD 同步由其他控制器管理的特定欄位 (例如 HPA 管理複本):

spec: ignoreDifferences: - group: apps kind: Deployment jsonPointers: - /spec/replicas

如需忽略模式和欄位排除的詳細資訊,請參閱 Argo CD 文件中的差異自訂

多環境部署

將相同的應用程式部署到多個環境:

開發

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app-dev namespace: argocd spec: project: default source: repoURL: https://github.com/example/my-app targetRevision: develop path: overlays/development destination: server: arn:aws:eks:us-west-2:111122223333:cluster/dev-cluster namespace: my-app

生產

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app-prod namespace: argocd spec: project: default source: repoURL: https://github.com/example/my-app targetRevision: main path: overlays/production destination: server: arn:aws:eks:us-west-2:111122223333:cluster/prod-cluster namespace: my-app syncPolicy: automated: prune: true selfHeal: true

監控和管理應用程式

檢視應用程式狀態

kubectl get application my-app -n argocd

存取 Argo CD UI

透過 EKS 主控台開啟 Argo CD UI,以檢視應用程式拓撲、同步狀態、資源運作狀態和部署歷史記錄。如需 UI 存取指示使用 Argo CD,請參閱 。

轉返應用程式

使用 Argo CD UI 或將應用程式規格targetRevision中的 更新為先前的 Git 遞交或標籤,轉返至先前的修訂。

其他資源