When you use a master instance of ACK One 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 master instance to distribute applications
by specifying the cluster name or a label as the cluster selector.
Prerequisites
-
The kubeconfig file of the master instance is obtained from the ACK One console by using an account with the developer role. A kubectl client is connected to the
master instance.
-
Namespaces and resource quotas are configured by the master instance administrator.
For more information, see Manage namespaces and resource quotas.
- Multiple ACK clusters are associated with the master instance. For more information,
see Associate clusters with a master instance.
- The AMC command-line tool is installed. For more information, see Use AMC.
Method 1: Specify a cluster name
- Run the following command to query the names of the clusters that are associated with
a master 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
- Create a
Policy
object with 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 name of the cluster to which you want to distribute applications. Specify multiple cluster names in the following format: ["<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 id to distribute applications to multiple clusters.
|
Method 2: Specify a label as the cluster id
- Run the following command to query the names of the clusters that are associated with
a master 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
- Run the following command to add a label to a cluster that is associated with the
master instance:
Replace
<clusterid>
with the name of the cluster to which you want to add the label. Replace
env=production1
with the actual key-value pair that you want to add.
kubectl label managedclusters <clusterid> env=production1
- Create a
Policy
object with the following code block. Set the clusterSelector
parameter to the label that you added as 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 as cluster selectors. The specified labels are used to select
clusters that are associated with the master instance.
|