All Products
Search
Document Center

:Select a cluster to distribute applications

Last Updated:Dec 06, 2023

When you use a Distributed Cloud Container Platform for Kubernetes (ACK One) Fleet instance to distribute applications, you must select the cluster to which you want to distribute the applications. This topic describes how to select a cluster that is associated with a Fleet instance to distribute applications by specifying the cluster ID or specifying a label in the cluster selector.

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.

Method 1: Specify the ID of an associated cluster

  1. Run the following command to query the IDs of the clusters that are associated with the Fleet instance. The NAME column displays the IDs of the clusters.

    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. Create a Policy object based on the following code block.

    Replace <clusterid1> with the ID of the cluster to which you want to distribute applications.

    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: cluster-beijing
      namespace: demo
    type: topology
    properties:
      clusters: ["<clusterid1>"]   # The ID of the cluster to which you want to distribute applications. Specify multiple cluster IDs in the following format: clusters: ["<clusterid1>", "<clusterid2>"...]
    .

    Parameter

    Description

    type: topology

    • A Policy object of the Topology type allows you to define the clusters to which applications are distributed.

    • A Policy object of the Override type allows you to override the configurations of applications.

    properties. clusters

    You can specify multiple cluster IDs to distribute applications to the clusters.

Method 2: Specify a label in the cluster selector

  1. Run the following command to query the IDs of the clusters that are associated with the Fleet instance. The NAME column displays the IDs of the clusters.

    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. Run the following command to add a label to a cluster that is associated with the Fleet instance:

    Replace <clusterid> with the ID of the cluster to which you want to add the label. Replace env=production1 with the key-value pair that you want to add.

    kubectl label managedclusters <clusterid> env=production1
  3. Create a Policy object based on the following code block. Set the clusterSelector parameter to the label that you specified in the cluster selector.

    Replace env: production1 with the key-value pair that you added.

    apiVersion: core.oam.dev/v1alpha1
    kind: Policy
    metadata:
      name: cluster-test
      namespace: demo
    type: topology
    properties:
      clusterSelector:   
        env: production1     # The key-value pair that is used to select the cluster. If you want to select more than one cluster, add more key-value pairs below this key-value pair.    

    Parameter

    Description

    type: topology

    • A Policy object of the Topology type allows you to define the clusters to which applications are distributed.

    • A Policy object of the Override type allows you to override the configurations of applications.

    properties: clusterSelector

    You can specify labels in the cluster selector. The specified labels are used to select clusters that are associated with the Fleet instance.