This topic describes how to use GitOps to manage applications. You can use GitOps to create, deploy, update, and roll back applications.
Prerequisites
You are logged on to the GitOps system. For more information, see Log on to the GitOps system.
A Git repository is added to the GitOps system. For more information, see Add repositories.
Multiple clusters are associated with the Fleet instance. For more information, see Associate clusters with a Fleet instance.
Create and deploy an application
In this topic, an application named echo-server-demo is created and deployed to a Container Service for Kubernetes (ACK) cluster. The address of the API server of the ACK cluster is https://47.97.XX.XX:6443
.
If you cannot access GitHub due to network issues, replace https://github.com/AliyunContainerService/gitops-demo.git
with https://code.aliyun.com/shuwei.hsw/gitops-demo.git
.
Use the 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 of the ArgoCD UI, click Applications and then click + NEW APP.
In the panel that appears, 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 need to manually synchronize changes from the Git repository to the cluster where the application is deployed.
Automatic: ArgoCD Server scans the Git repository every 3 minutes and synchronizes changes to the cluster where the application is deployed.
SYNC OPTIONS
Select AUTO-CREATE NAMESPACE.
SOURCE
Repository URL
Select a Git repository from the drop-down list. In this example, https://github.com/AliyunContainerService/gitops-demo.git is selected.
Revision
HEAD
Path
manifests/helm/echo-server
DESTINATION
Cluster URL/Cluster Name
Select a cluster from the drop-down list.
Namespace
echo-server-demo
HELM
VALUES FILES
values.yaml
After the application named echo-server-demo is created, you can view the status of the application on the Application page.
If SYNC POLICY is set to Manual, you need to click SYNC to manually deploy the application in the specified cluster. After the status of the application changes to Healthy and Synced, the application is deployed.
Use the Argo CD CLI
Run the following command to create an application named echo-server-demo:
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 none
Expected output:
application 'echo-server-demo' created
The following table describes the parameters in the command.
Parameter
Description
repo
The address of the Git repository that is used to create the application.
path
The subdirectory of the YAML file of the echo-server-demo application.
dest-server
The endpoint of the API server of the ACK cluster.
dest-namespace
The namespace in which the application is deployed.
sync-policy
The synchronization policy of the application. Default value:
none
. Valid values:auto
andnone
.auto
: The GitOps system periodically scans the Git repository for changes in the echo-server application and automatically synchronizes the changes to the application deployed in the specified cluster.none
: You must manually synchronize changes to the application deployed in the specified cluster.
Run the following command to deploy the echo-server-demo application to the specified cluster:
argocd app sync echo-server-demo
Expected 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
View applications
Use the Argo CD console
In the left-side navigation pane of the Argo CD UI, click Applications to view all applications.
Click the name of the application to view the application details. The details page displays the topology and status of Kubernetes resources used by the application.
Use the Argo CD CLI
Run the following command to query applications that are deployed:
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
The GitOps application release framework requires you to update the source code of an application in the Git repository if you want to update the application. After you commit the updated code to the Git repository, you can synchronize the change to the cluster.
Commit changes to the Git repository.
Run the following command to synchronize the changes to the application deployed in the specified 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 IP address of the application.
Expected output:
"Hello Echo Server v2.0"
Roll back an application
Use the Argo CD console
In the left-side navigation pane of the Argo CD UI, click Applications. In the application list, find the echo-server-demo application and click its name.
On the application details page, click HISTORY AND ROLLBACK. On the historical version page that appears, select a historical version and click Rollback in the upper-right corner.
After the rollback is complete, return to the details page and check the version of the application.
Use the Argo CD CLI
Run the following command to view the available historical versions:
argocd app history echo-server-demo
Expected output:
ID DATE REVISION 0 2022-10-17 16:43:20 +0800 CST (02af62b) 1 2022-10-17 16:52:49 +0800 CST (56ae547)
56ae547
in theREVISION
column is the current version. The ID of the current version is 1.Run the following command to roll back the application to version
02af62b
in theREVISION
column.argocd app rollback echo-server-demo 0
After the rollback is completed, 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 IP address of the application.
Expected output:
"Hello Echo Server v1.0"