All Products
Search
Document Center

:Migrate applications created from orchestration templates

Last Updated:Aug 25, 2023

Container Service for Kubernetes (ACK) GitOps is developed based on open source Argo CD. You cannot create applications from orchestration templates in ACK GitOps. To migrate applications that are created from orchestration templates, you must submit the orchestration templates to Git repositories, create GitOps applications, obtain the orchestration templates from Git repositories, and then distribute the GitOps applications to associated clusters. You can update orchestration templates in Git repositories to update applications. You can manually update the applications in associated clusters or configure GitOps to automatically update the applications in associated clusters. This topic describes how to migrate applications created from orchestration templates to ACK One GitOps.

Table of contents

Prerequisites

Step 1: Obtain orchestration templates from Application Center

  1. Log on to the ACK console and choose Multi-cluster > Application Center in the left-side navigation pane.

  2. On the Application Center page, you can view information about the applications that you want to migrate.

    1. Select a master cluster from the Master Cluster drop-down list.

    2. Find the application that you want to migrate and click the More icon to the left of the application name.

    3. Select a cluster and click View in YAML to obtain the orchestration template that is used to deploy the application in the cluster.

      You must obtain the orchestration template for each cluster where the application is deployed.

      编排模板1.png

Step 2: Associate clusters with a master instance

Associate all the clusters (obtained in Step 1) where the application is deployed with a master instance. For more information, see Associate clusters with a master instance.

Step 3: Submit orchestration templates to a Git repository

We recommend that you create a new Git repository to store the orchestration templates. You can also store the orchestration templates in an existing Git repository.

  1. Create a new directory named application1 in the Git repository to store the orchestration template of Application1.

  2. Create a separate subdirectory in the application1 directory for each cluster where Application1 is deployed.

  3. Create a YAML file in each subdirectory and specify the orchestration template (obtained in Step 1) for the corresponding cluster. Example:

    .
    └── applicatioin1
        ├── cluster-hk
        │   └── template.yaml
        └── cluster-hk-1
            └── template.yaml
  4. Add the Git repository to ACK One GitOps. For more information, see Add Git repositories to ACK One GitOps.

Step 4: Migrate applications

  1. Use the Argo CD CLI to access the master cluster:

    1. Run the following command in the master cluster to import environment variables:

      export ARGOCD_OPTS='--port-forward-namespace appcenter --plaintext'
    2. Run the following command in the master cluster to query applications in the cluster:

      argocd app list | grep application1

      Expected output:

      NAME                 CLUSTER                     NAMESPACE  PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO        PATH  TARGET
      application1-451a02  https://8.217.XX.XX:6443   default    default  Synced  Healthy  <none>      <none>      aliyun.com        HEAD
      application1-46b9bb  https://172.17.XX.XX:6443  default    default  Synced  Healthy  <none>      <none>      aliyun.com        HEAD

      The output indicates that two ArgoCD Applications are created for Application1. Each ArgoCD Application corresponds to a separate cluster. The output also includes the API server address of each cluster.

  2. Run the following command on the master instance to obtain the API server addresses of the clusters that are associated with the master instance:

    argocd cluster list

    Expected output:

    SERVER                          NAME                                          VERSION  STATUS      MESSAGE                                                  PROJECT
    https://172.17.XX.XX:6443       c03a223407a044cc7b0a9cc1c0a45****-cluster-hk  1.24+    Successful
    https://172.17.XX.XX:6443       c3f218b3af71b44c189485abd4846****-cluster-hk-1           Unknown     Cluster has no applications and is not being monitored.
    https://kubernetes.default.svc  in-cluster                                              Unknown     Cluster has no applications and is not being monitored.
  3. Run the following command on the master instance to export the manifests of the application1-451a02 ArgoCD Application, which corresponds to the cluster-hk cluster.

    kubectl -n appcenter get application application1-451a02 -oyaml > application1-cluster-hk.yaml
  4. Modify the application1-cluster-hk.yaml file that is exported in the previous step.

    1. The application1-451a02 ArgoCD Application corresponds to the cluster-hk. The API server address of the cluster-hk cluster is https://8.217.XX.XX:6443, which is different from the API server address https://172.17.XX.XX:6443 that is used to associate cluster-hk with the master instance. You must run the following command to replace https://8.217.XX.XX:6443 with https://172.17.XX.XX:6443 in the application1-cluster-hk.yaml file.

      sed -i "s/8.217.XX.XX/172.17.XX.XX/g" application1-cluster-hk.yaml
    2. Run the following shell command to change the value of the namespace parameter in the application1-cluster-hk.yaml file to argocd:

      sed -i "s/namespace: appcenter/namespace: argocd/g" application1-cluster-hk.yaml
    3. Run the following shell command to change the value of the name parameter in the application1-cluster-hk.yaml file to application1-cluster-hk:

      sed -i "s/name: application1-451a02/name: application1-cluster-hk/g" application1-cluster-hk.yaml
    4. Change the value of the spec.source parameter in the application1-cluster-hk.yaml file to the Git repository in Step 3.

      YAML template before modification:

      apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: application1-cluster-hk
        namespace: appcenter
      spec:
        destination:
          namespace: default
          server: https://172.17.XX.XX:6443
        project: default
        # Change the value of the spec.source parameter to the the Git repository. 
        source:
          repoURL: aliyun.com
          targetRevision: HEAD
          template:
            aliUID: "14****01"
            id: 3e****af

      YAML template after modification:

      apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: application1-cluster-hk
        namespace: appcenter
      spec:
        destination:
          namespace: default
          server: https://172.17.XX.XX:6443
        project: default
        # The Git repository. 
        source:
          # The subdirectory for a cluster. 
          path: application1/cluster-hk
          # The Git repository address. You can view Git repositories by running the argocd repo list command. 
          repoURL: https://github.com/AliyunContainerService/gitops-demo
          # The branch of the Git repository. 
          targetRevision: one-demo
    5. Delete all settings in the status parameter in the application1-cluster-hk.yaml file.

  5. Migrate application manifests to the master instance.

    1. Run the following command on the master instance to create an Argo CD Application by using the application1-cluster-hk.yaml file:

      kubectl apply -f application1-cluster-hk.yaml
    2. Run the following command on the master instance to query Argo CD Applications and their status:

      argocd app list

      Expected output:

      NAME                     CLUSTER                     NAMESPACE        PROJECT  STATUS     HEALTH   SYNCPOLICY  CONDITIONS                REPO                                                       PATH                     TARGET
      application1-cluster-hk  https://172.17.XX.XX:6443  default          default  OutOfSync  Healthy  <none>      SharedResourceWarning(2)  https://github.com/AliyunContainerService/gitops-demo      application1/cluster-hk  one-demo
  6. Run the following command in the master cluster to delete applications from Application Center:

    Important

    You must specify --cascade=false in the delete command. Otherwise, the Kubernetes resources trelated to the applications are also deleted.

    argocd app delete application1-451a02 --cascade=false
  7. Run the following command on the master instance to synchronize the application. Check the output to verify that the application is in the Synced state.

    argocd app sync application1-cluster-hk

    Expected output:

    argocd app list
    NAME                     CLUSTER                     NAMESPACE        PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                                       PATH                     TARGET
    application1-cluster-hk  https://172.17.XX.XX:6443  default          default  Synced  Healthy  <none>      <none>      https://github.com/AliyunContainerService/gitops-demo      application1/cluster-hk  one-demo
  8. Repeat Step 3 to Step 7 to migrate the remaining applications.