Application management

更新时间:
复制 MD 格式

This topic describes how to use a GitOps system to create, deploy, update, and roll back applications.

Prerequisites

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.

Note

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

  1. Log on to the Argo CD UI. For more information, see Use the Argo CD UI to log on to Argo CD.

  2. In the left-side navigation pane, select Applications, and then click + NEW APP.

  3. 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

  4. 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

  1. Run the following command to create the echo-server-demo application.

    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 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 are auto and none.

    • 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.

  2. Run the following command to sync and deploy the echo-server-demo application to the target 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

Application list

Argo CD console

  1. In the left-side navigation pane, select Applications to view the application list.

  2. Click the echo-server-demo application 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.

  1. Commit the changes to the Git repository.

  2. Run the following command to sync and deploy the latest version of the application to the target cluster.

    argocd app sync echo-server-demo
  3. 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

  1. In the left-side navigation pane, select Applications. Find the echo-server-demo application and click its name.

  2. 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.

  3. After the rollback completes, return to the application details page and verify the application version.

Argo CD CLI

  1. 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)

    The current REVISION is 56ae547, and the serial number is 1.

  2. Run the following command to roll back the application to the historical version where REVISION is 02af62b.

    argocd app rollback echo-server-demo 0

    After the rollback completes, verify that you can still access the application.

  3. 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"