This topic describes how to use a GitOps system to create, deploy, update, and roll back applications.
Prerequisites
-
You have logged on to the GitOps system.
-
You have added a Git repository.
The Fleet instance has added two associated clusters (service provider cluster, service consumer cluster).
Create and deploy an application
This section explains how to create the echo-server-demo sample application and deploy it to an ACK cluster whose API server address ishttps://47.97.XX.XX:6443.
If you cannot access GitHub due to network issues, you can replacehttps://github.com/AliyunContainerService/gitops-demo.git withhttps://code.aliyun.com/shuwei.hsw/gitops-demo.git.
Argo CD console
-
Log on to the Argo CD UI. For more information, see Use the Argo CD UI to log on to Argo CD.
-
In the left-side navigation pane, select Applications, and then click + NEW APP.
-
In the panel, configure the following parameters and click CREATE.
Section
Parameter
Value
GENERAL
Application Name
echo-server-demo
Project Name
default
SYNC POLICY
Select Automatic from the drop-down list.
Valid values:
-
Manual: You must manually trigger a sync to deploy changes from the Git repository to the target cluster.
-
Automatic: The Argo CD server automatically checks for changes in the Git repository every 3 minutes and deploys them to the target cluster.
SYNC OPTIONS
Select the AUTO-CREATE NAMESPACE checkbox.
SOURCE
Repository URL
Select an existing Git repository. In this example, select https://github.com/AliyunContainerService/gitops-demo.git.
Revision
HEAD
Path
manifests/helm/echo-server
DESTINATION
Cluster URL/Cluster Name
Select the target cluster.
Namespace
echo-server-demo
HELM
VALUES FILES
values.yaml
-
-
After you create the application, you can view its status on the Applications page.
If you set SYNC POLICY to Manual, you must click SYNC to deploy the application to the target cluster. The application is synchronized when its STATUS is Healthy and Synced.
Argo CD CLI
-
Run the following command to create the
echo-server-demoapplication.argocd app create echo-server-demo --repo https://github.com/AliyunContainerService/gitops-demo.git --path manifests/directory/production --dest-namespace echo-server-demo --dest-server https://47.97.XX.XX:6443 --sync-policy noneExpected output:
application 'echo-server-demo' createdThe following table describes the command parameters.
Parameter
Description
repo
The URL of the Git repository for the application.
path
The path to the application manifests in the repository.
dest-server
The API server address of the target cluster.
dest-namespace
The namespace in the target cluster.
sync-policy
The application's sync policy. The default value is
none. Valid values areautoandnone.-
auto: Argo CD periodically checks the Git repository for changes and automatically deploys them to the target cluster. -
none: You must manually trigger a sync to deploy the application to the target cluster.
-
-
Run the following command to sync and deploy the
echo-server-demoapplication to the target cluster.argocd app sync echo-server-demoExpected output:
TIMESTAMP GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE 2022-10-17T16:43:20+08:00 apps Deployment echo-server-demo echo-server OutOfSync Missing 2022-10-17T16:43:20+08:00 Service echo-server-demo echo-server OutOfSync Missing 2022-10-17T16:43:20+08:00 Service echo-server-demo echo-server Synced Progressing 2022-10-17T16:43:20+08:00 Service echo-server-demo echo-server Synced Progressing service/echo-server-demo created 2022-10-17T16:43:20+08:00 apps Deployment echo-server-demo echo-server OutOfSync Missing deployment.apps/echo-server-demo created 2022-10-17T16:43:20+08:00 apps Deployment echo-server-demo echo-server Synced Progressing deployment.apps/echo-server-demo created Name: echo-server-demo Project: default Server: https://47.97.XX.XX:6443 Namespace: echo-server-demo URL: https://127.0.0.1:65384/applications/echo-server-demo Repo: https://github.com/AliyunContainerService/gitops-demo.git Target: Path: manifests/directory/production SyncWindow: Sync Allowed Sync Policy: <none> Sync Status: Synced to (02af62b) Health Status: Progressing Operation: Sync Sync Revision: 02af62bf21e76f53ebfcc282c45865d2308c**** Phase: Succeeded Start: 2022-10-17 16:43:19 +0800 CST Finished: 2022-10-17 16:43:20 +0800 CST Duration: 1s Message: successfully synced (all tasks run) GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE Service echo-server-demo echo-server-demo Synced Progressing service/echo-server-demo created apps Deployment echo-server-demo echo-server-demo Synced Progressing deployment.apps/echo-server-demo created
Application list
Argo CD console
-
In the left-side navigation pane, select Applications to view the application list.
-
Click the
echo-server-demoapplication name to view its details, including the resource topology and status of the related Kubernetes resources.An APP HEALTH of Healthy and a SYNC STATUS of Synced indicate that the application is synchronized and running correctly. In the resource topology diagram,
echo-server-demo(Application) branches into two paths: the upper path connects to Service, then to Endpoints and EndpointSlice; the lower path connects to Deployment → ReplicaSet → Pod (Running).
Argo CD CLI
Run the following command to view the application list.
argocd app list
Expected output:
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
echo-server https://47.97.XX.XX:6443 echo-server-demo default Synced Healthy <none> <none> https://github.com/AliyunContainerService/gitops-demo.git manifests/directory/production
Update an application
In the GitOps model, the Git repository is the single source of truth. You must commit all changes to an application to the Git repository and then synchronize them to the target cluster.
-
Commit the changes to the Git repository.
-
Run the following command to sync and deploy the latest version of the application to the target cluster.
argocd app sync echo-server-demo -
Run the following command to access the application.
curl XX.XX.XX.XX:8080/version # Replace XX.XX.XX.XX with the application's IP address.Expected output:
"Hello Echo Server v2.0"
Roll back an application
Argo CD console
-
In the left-side navigation pane, select Applications. Find the
echo-server-demoapplication and click its name. -
On the application details page, click HISTORY AND ROLLBACK. On the HISTORY AND ROLLBACK panel, select the version to which you want to roll back, and then click Rollback in the upper-right corner.
-
After the rollback completes, return to the application details page and verify the application version.
Argo CD CLI
-
Run the following command to view the available historical versions.
argocd app history echo-server-demoExpected output:
ID DATE REVISION 0 2022-10-17 16:43:20 +0800 CST (02af62b) 1 2022-10-17 16:52:49 +0800 CST (56ae547)The current
REVISIONis56ae547, and the serial number is 1. -
Run the following command to roll back the application to the historical version where
REVISIONis02af62b.argocd app rollback echo-server-demo 0After the rollback completes, verify that you can still access the application.
-
Run the following command to access the application.
curl XX.XX.XX.XX:8080/version # Replace XX.XX.XX.XX with the application's IP address.Expected output:
"Hello Echo Server v1.0"