Bantu tingkatkan halaman ini
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Untuk berkontribusi pada panduan pengguna ini, pilih Edit halaman ini pada GitHub tautan yang terletak di panel kanan setiap halaman.
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan ApplicationSets
ApplicationSets menghasilkan beberapa Aplikasi dari template, memungkinkan Anda untuk menyebarkan aplikasi yang sama di beberapa cluster, lingkungan, atau ruang nama dengan definisi sumber daya tunggal.
Prasyarat
-
Cluster EKS dengan kemampuan Argo CD dibuat
-
Akses repositori dikonfigurasi (lihat) Konfigurasikan akses repositori
-
kubectldikonfigurasi untuk berkomunikasi dengan cluster Anda
catatan
Beberapa cluster target tidak diperlukan untuk ApplicationSets. Anda dapat menggunakan generator selain generator cluster (seperti generator list, git, atau matriks) untuk menyebarkan aplikasi tanpa cluster jarak jauh.
Bagaimana cara ApplicationSets kerja
ApplicationSets gunakan generator untuk menghasilkan parameter, lalu terapkan parameter tersebut ke template Aplikasi. Setiap set parameter yang dihasilkan menciptakan satu Aplikasi.
Generator umum untuk penerapan EKS:
-
Generator daftar - Secara eksplisit mendefinisikan cluster dan parameter untuk setiap lingkungan
-
Generator cluster - Secara otomatis menyebarkan ke semua cluster terdaftar
-
Generator Git - Hasilkan Aplikasi dari struktur repositori
-
Generator matriks - Gabungkan generator untuk penerapan multi-dimensi
-
Gabungkan generator - Gabungkan parameter dari beberapa generator
Untuk referensi generator lengkap, lihat ApplicationSet Dokumentasi
Daftar Generator
Terapkan ke beberapa cluster dengan konfigurasi eksplisit:
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
catatan
Gunakan destination.name dengan nama cluster untuk keterbacaan yang lebih baik. destination.serverBidang ini juga berfungsi dengan cluster EKS ARNs jika diperlukan.
Ini menciptakan tiga Aplikasi:guestbook-dev,guestbook-staging, danguestbook-prod.
Generator cluster
Terapkan ke semua cluster terdaftar secara otomatis:
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
Ini secara otomatis membuat Aplikasi untuk setiap cluster terdaftar.
Cluster filter:
Gunakan matchLabels untuk menyertakan cluster tertentu, atau matchExpressions untuk mengecualikan cluster:
spec: generators: - clusters: selector: matchLabels: environment: production matchExpressions: - key: skip-appset operator: DoesNotExist
Generator Git
Generator Git membuat Aplikasi berdasarkan struktur repositori:
-
Generator direktori - Menyebarkan setiap direktori sebagai Aplikasi terpisah (berguna untuk layanan mikro)
-
Generator file - Hasilkan Aplikasi dari file parameter (berguna untuk penyebaran multi-penyewa)
Contoh: Penyebaran Microservices
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
Untuk detail tentang generator Git dan konfigurasi berbasis file, lihat Git Generator dalam dokumentasi
Generator matriks
Gabungkan beberapa generator untuk digunakan di berbagai dimensi (lingkungan × cluster):
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}}'
Untuk detail tentang menggabungkan generator, lihat Matrix Generator
Penyebaran multi-wilayah
Terapkan ke cluster di beberapa wilayah:
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
Mengelola ApplicationSets
Lihat ApplicationSets dan dihasilkan Aplikasi:
kubectl get applicationsets -n argocd kubectl get applications -n argocd -l argocd.argoproj.io/application-set-name=<applicationset-name>
Perbarui ApplicationSet:
Ubah ApplicationSet spesifikasi dan aplikasikan kembali. Argo CD secara otomatis memperbarui semua Aplikasi yang dihasilkan:
kubectl apply -f applicationset.yaml
Hapus sebuah ApplicationSet:
kubectl delete applicationset <name> -n argocd
Awas
Menghapus ApplicationSet menghapus semua Aplikasi yang dihasilkan. Jika Aplikasi tersebut memilikiprune: true, sumber daya mereka juga akan dihapus dari cluster target.
Untuk mempertahankan sumber daya yang digunakan saat menghapus ApplicationSet, setel .syncPolicy.preserveResourcesOnDeletion ke true dalam spesifikasi. ApplicationSet Untuk informasi lebih lanjut, lihat Pemangkasan Aplikasi & Penghapusan Sumber Daya
penting
ApplicationSets Fitur Argo CD memiliki pertimbangan keamanan yang harus Anda ketahui sebelum menggunakannya. ApplicationSets Untuk informasi selengkapnya, lihat ApplicationSet Keamanan
Sumber daya tambahan
-
Bekerja dengan Proyek CD Argo- Mengatur ApplicationSets dengan Proyek
-
Buat Aplikasi- Memahami konfigurasi Aplikasi
-
ApplicationSet Dokumentasi
- Referensi dan pola generator lengkap -
Referensi Generator
- Spesifikasi generator terperinci