All Products
Search
Document Center

Container Service for Kubernetes:Application management

Last Updated:Feb 27, 2024

This topic describes how to use GitOps to manage applications. You can use GitOps to create, deploy, update, and roll back applications.

Prerequisites

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.

Note

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

  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 of the ArgoCD UI, click Applications and then click + NEW APP.

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

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

    image.png

Use the Argo CD CLI

  1. 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 and none.

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

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

  1. In the left-side navigation pane of the Argo CD UI, click Applications to view all applications.

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

    image.png

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.

  1. Commit changes to the Git repository.

  2. Run the following command to synchronize the changes to the application deployed in the specified 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 IP address of the application.

    Expected output:

    "Hello Echo Server v2.0"

Roll back an application

Use the Argo CD console

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

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

    image

  3. After the rollback is complete, return to the details page and check the version of the application.

Use the 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)

    56ae547 in the REVISION column is the current version. The ID of the current version is 1.

  2. Run the following command to roll back the application to version 02af62b in the REVISION column.

    argocd app rollback echo-server-demo 0

    After the rollback is completed, 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 IP address of the application.

    Expected output:

    "Hello Echo Server v1.0"