An ApplicationSet allows you to create and deploy one or more applications to multiple clusters by using one orchestration template. This topic describes how to use an ApplicationSet to create multiple applications.
Prerequisites
You are logged on to the GitOps system. For more information, see Log on to the GitOps system.
kubectl is installed and the kubeconfig file used to log on to the ACK One Fleet instance that you want to use is obtained. The default path of the kubeconfig file is ~/.kube/config.
Examples
In this example, an echo-server application is deployed to Cluster Production and Cluster Staging. The following content shows the structure of the manifests directory in the Git repository used to deploy the echo-server application:
.
├── Dockerfile
├── go.mod
├── go.sum
├── main.go
└── manifests
└── directory
├── production
│ ├── deployment.yaml
│ └── service.yaml
└── staging
├── deployment.yaml
└── service.yaml
The echo-server application in Cluster Production is different from the echo-server application in Cluster Staging in terms of the application version and how the application is exposed. Therefore, the subdirectories production and staging are created to separate the orchestration templates for the echo-server application in Cluster Production and the orchestration templates for the echo-server application in Cluster Production.
Procedure
Create a file named applicationset.yaml based on the following content:
The ApplicationSet is used to create two applications named
production-echo-server
andstaging-echo-server
. Theproduction-echo-server
application is deployed based on the manifest file in the subdirectory manifests/directory/production. Thestaging-echo-server
application is deployed based on the manifest file in the subdirectory manifests/directory/staging.apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: echo-server spec: generators: - list: elements: - cluster: production url: https://47.91.XX.XX:6443 - cluster: staging url: https://47.111.XX.XX:6443 template: metadata: name: '{{cluster}}-echo-server' spec: project: default source: repoURL: https://code.aliyun.com/shuwei.hsw/echo-server.git targetRevision: main path: manifests/directory/{{cluster}} destination: server: '{{url}}' namespace: multi-echo-server
Run the following command to deploy the ApplicationSet:
kubectl -n argocd apply -f applicationset.yaml
Run the following command to query the applications that are created:
kubectl -n argocd get application
Expected output:
NAME SYNC STATUS HEALTH STATUS production-echo-server OutOfSync Missing staging-echo-server OutOfSync Missing
Run the following command to synchronize the applications to the clusters:
argocd app sync production-echo-server staging-echo-server
Test access to the echo-server application.
Run the following command to access the echo-server application in Cluster Production:
curl XX.XX.XX.XX:8080/version #Replace XX.XX.XX.XX with the IP address of the echo-server application.
Expected output:
"Hello Echo Server v1.0"
Run the following command to access the echo-server application in Cluster Staging:
curl XX.XX.XX.XX:8080/version #Replace XX.XX.XX.XX with the IP address of the echo-server application.
Expected output:
"Hello Echo Server v2.0"
References
For more information about how to use ApplicationSets, see ApplicationSet.