All Products
Search
Document Center

:Use canary releases to deploy an application across clusters

Last Updated:Dec 04, 2023

Distributed Cloud Container Platform for Kubernetes (ACK One) provides the workflows feature. This feature allows you to use canary releases to deploy an application across clusters. For example, you can first deploy an application to the testing cluster. After the application is verified, you can deploy the application to the production cluster. This reduces the risks in application releases. This topic describes how to use canary releases on a Fleet instance to deploy an application across clusters.

Prerequisites

  • The Fleet management feature is enabled. For more information, see Enable Fleet management.

  • Multiple clusters are associated with the Fleet instance. For more information, see Associate clusters with a Fleet instance.

  • The kubeconfig file of the Fleet instance is obtained in the ACK One console and a kubectl client is connected to the Fleet instance.

  • The AMC command-line tool is installed. For more information, see Use AMC.

Procedure

  1. Create a file named app-meta.yaml with the following content. The file defines the Kubernetes resources that are required to deploy an application.
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: demo
      name: demo
      namespace: demo
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: demo
      template:
        metadata:
          labels:
            app: demo
        spec:
          containers:
          - image: registry.cn-hangzhou.aliyuncs.com/acs/rollouts-demo:red
            name: demo
  2. Run the following command to deploy an application named demo on a master instance:
    kubectl apply -f app-meta.yaml
  3. Create a file named policy-topology.yaml and copy the following content to the file: Specify the testing cluster cluster-test and the production cluster cluster-prod as the destination clusters.

    1. Run the following command to query the clusters associated with the Fleet instance. Confirm the destination clusters to which the application will be deployed.

      kubectl get managedclusters

      Expected output:

      NAME                     HUB ACCEPTED   MANAGED CLUSTER URLS   JOINED   AVAILABLE   AGE
      managedcluster-c5***z9   true                                  True     True        12d
      managedcluster-c1***e5   true                                  True     True        12d
    2. Select the destination clusters and replace <clusterid1> and <clusterid2> in the example with the IDs of the destination clusters.

    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: cluster-test
      namespace: demo
    type: topology
    properties:
      clusters: ["<clusterid1>"]
    ---
    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: cluster-prod
      namespace: demo
    type: topology
    properties:
      clusters: ["<clusterid2>"]
  4. Run the following command to apply the configurations in the policy-topology.yaml file:
    kubectl apply -f policy-topology.yaml
  5. Create a file named workflow.yaml and copy the following content to the file. The file defines a workflow.

    apiVersion: core.oam.dev/v1alpha1
    kind: Workflow
    metadata:
      name: deploy-demo
      namespace: demo
    steps:
      - type: deploy
        name: deploy-test
        properties:
          policies: ["cluster-test"]
      - type: deploy
        name: deploy-prod
        properties:
          auto: false
          policies: ["cluster-prod"]
    Note

    Add auto: false below deploy-prod in the workflow. After this setting is added, you need to manually confirm the deploy-pod step before the step can be performed.

  6. Run the following command to deploy a multi-cluster application workflow on the Fleet instance:

    kubectl apply -f workflow.yaml
  7. Create a file named app.yaml with the following content. The file defines the application.
    apiVersion: core.oam.dev/v1beta1
    kind: Application
    metadata:
      name: demo
      namespace: demo
      annotations:
        app.oam.dev/publishVersion: version1
    spec:
      components:
        - name: demo
          type: ref-objects
          properties:
            objects:
              - apiVersion: apps/v1
                kind: Deployment
                name: demo
      workflow:
        ref: deploy-demo
    ParameterDescription
    annotations: app.oam.dev/publishVersionThe version of the application. If an application or the Kubernetes resources that are used by an application are updated, you must change the value of this parameter to trigger the master instance to synchronize the updates to the clusters.
    components. type: ref-objectsThe apiVersion, kind, and name parameters are used to reference Kubernetes resources in the same namespace. The master instance deploys these resources in the specified clusters.
    • ACK One supports the following Kubernetes resources: Deployment/apps/v1, Secret/v1, ConfigMap/v1, and Ingress/networking.k8s.io/v1.
    • If you require other resources, Submit a ticket to contact the ACK One team.
    workflow. refSpecify the workflow that is used to deploy the application.
  8. Run the following command to deploy the application demo on the master instance:
    kubectl apply -f app.yaml
  9. Run the following command to query the deployment progress of the application.

    The output shows that the application named demo is in the workflowSuspending state.

    kubectl get app demo -n demo

    Expected output:

    NAME   COMPONENT   TYPE          PHASE                HEALTHY   STATUS   AGE
    demo   demo        ref-objects   workflowSuspending   true               38s
  10. Run the following command to query the status of the Deployment in both clusters.

    Replace <clusterid1> and <clusterid2> with the IDs of the destination clusters. The output shows that the Deployment is deployed in the testing cluster but is not deployed in the production cluster.

    • Run the following command to query the status of the Deployment in the cluster cluster-test:

      kubectl amc get deployment demo -n demo -m <clusterid1>

      Expected output:

      Run on ManagedCluster <clusterid1>
      NAME   READY   UP-TO-DATE   AVAILABLE   AGE
      demo   1/1     1            1           2m
    • Run the following command to query the status of the Deployment in the cluster cluster-prod:

      kubectl amc get deployment demo -n demo -m <clusterid2>

      Expected output:

      Run on ManagedCluster <clusterid2>
      Error from server (NotFound): deployments.apps "demo" not found
  11. Run the following command to deploy the Deployment in the production cluster:

    kubectl amc workflow resume demo -n demo

    Expected output:

    Successfully resume workflow: demo
  12. Query the status of the Deployment in the production cluster.

    The output shows that the Deployment is deployed in the production cluster.

    kubectl amc get deployment demo -n demo -m <clusterid2>

    Expected output:

    Run on ManagedCluster <clusterid2>
    NAME   READY   UP-TO-DATE   AVAILABLE   AGE
    demo   1/1     1            1           8m