All Products
Search
Document Center

:Use different configurations to deploy an application across multiple clusters

Last Updated:Dec 05, 2023

Distributed Cloud Container Platform for Kubernetes (ACK One) allows you to use a Fleet instance to deploy an application across multiple clusters. You can also use different configurations to deploy the application across the clusters. For example, you can specify different numbers of replicated pods, OS images, or environment variables for the application. This topic describes how to use different configurations to deploy an application across multiple 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 and add the following content to the file. The file defines the Kubernetes resources that are required for deploying 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 the Fleet instance:

    kubectl apply -f app-meta.yaml
  3. Create a file named policy-topology.yaml and add the following content to the file. The clusters cluster-beijing and cluster-hangzhou are specified as the destination clusters in which the Kubernetes resources are deployed.

    1. Run the following command to query the clusters that are associated with the Fleet instance:

      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-beijing
        namespace: demo
      type: topology
      properties:
        clusters: ["<clusterid1>"]
      ---
      apiVersion: core.oam.dev/v1alpha1
      kind: Policy
      metadata:
        name: cluster-hangzhou
        namespace: demo
      type: topology
      properties:
        clusters: ["<clusterid2>"]

      Parameter

      Description

      type: topology

      Set the type of the policy to topology. A topology policy specifies the destinations to which Kubernetes resources are deployed.

      properties. clusters

      You can specify destinations only by cluster ID. Each destination can contain one or more clusters that are associated with the Fleet instance.

  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 policy-override.yaml and add the following content to the file. The number of replicated pods created by the Deployment is changed to a different value.

    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: override-replic-beijing
      namespace: demo
    type: override
    properties:
      components:
      - name: "demo"
        traits:
        - type: scaler
          properties:
            replicas: 3
    ---
    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: override-replic-hangzhou
      namespace: demo
    type: override
    properties:
      components:
      - name: "demo"
        traits:
        - type: scaler
          properties:
            replicas: 5

    Parameter

    Description

    type: override

    Set the type of the policy to override. You can use an override policy to override the configurations of an application.

    properties. components. name

    Specify the application whose configurations you want to override.

    properties. components.traits

    Specify the configuration item that you want to override. In this example, scaler is used to change the number of replicated pods that are created by the Deployment.

  6. Run the following command to deploy the application across multiple clusters by using different configurations:

    kubectl apply -f policy-override.yaml
  7. Create a file named workflow.yaml and add 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-bejing
        properties:
          policies: ["override-replic-beijing", "cluster-beijing"]
      - type: deploy
        name: deploy-hangzhou
        properties:
          policies: ["override-replic-hangzhou", "cluster-hangzhou"]

    Parameter

    Description

    type: deploy

    Define the Deploy step in the workflow.

    steps. properties. policies

    The policy that is used in the Deploy step. The policy specifies the overridden configurations and the clusters in which the overridden configurations are deployed.

  8. Run the following command to deploy the workflow on the Fleet instance. The workflow is used to deploy the application across multiple clusters.

    kubectl apply -f workflow.yaml
  9. Create a file named app.yaml and add the following content to the file. 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

    Parameter

    Description

    annotations: app.oam.dev/publishVersion

    The 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 Fleet instance to synchronize the updates to the clusters.

    components. type: ref-objects

    The apiVersion, kind, and name parameters are used to reference Kubernetes resources in the same namespace. The Fleet 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. ref

    Specify the workflow that is used to deploy the application.

  10. Run the following command to deploy the application demo on the Fleet instance:

    kubectl apply -f app.yaml
  11. Query the status of the application.

    • Run the following command to query the deployment progress of the application:

      kubectl get app demo -n demo

      Expected output:

      NAME   COMPONENT   TYPE          PHASE     HEALTHY   STATUS   AGE
      demo   demo        ref-objects   running   true               24m
    • Run the following command to query the numbers of replicated pods that are created by the Deployment in different destination clusters.

      Replace <clusterid1> with the ID of the cluster that you want to query. The output shows that the replicated pods are deployed as expected in the cluster.

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

      Expected output:

      Run on ManagedCluster <clusterid1>
      NAME   READY   UP-TO-DATE   AVAILABLE   AGE
      demo   3/3     3            3           28m
      kubectl amc get deployment demo -n demo -m <clusterid2>

      Expected output:

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