Skip to content

Commit

Permalink
Add multiplehubs solution and rename multiple-agents-hosted to multip…
Browse files Browse the repository at this point in the history
…le-agents (#626)

Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun authored Sep 23, 2024
1 parent 7772622 commit 233c61b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Manage a cluster with multiple hubs in hosted mode
# Manage a cluster with multiple agents in hosted mode

The scripts provided in this doc help you to setup an Open Cluster Management (OCM) environment with Kind clusters where a single cluster is managed by two hubs. The agents of the second hub runs in the hosted mode on a hostng cluster.
The scripts provided in this doc help you to setup an Open Cluster Management (OCM) environment with Kind clusters where a single cluster is managed by two hubs via two agents installed on the managed cluster. The agents of the second hub runs in the hosted mode on a hosting cluster.

## Prerequisite

Expand Down
2 changes: 1 addition & 1 deletion solutions/multiple-agents/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Manage a spoke installed with multiple agents connected to different hubs

The scripts provided in this document help you set up an Open Cluster Management (OCM) environment with Kind clusters, where a single cluster is managed by two hubs. The agents of the two hubs are all running in the default mode on the managed cluster under different namespaces.
The scripts provided in this document help you set up an Open Cluster Management (OCM) environment with Kind clusters, where a single cluster is managed by two hubs via two agents installed on the managed cluster. The agents of the two hubs are all running in the default mode on the managed cluster under different namespaces.

## Prerequisite

Expand Down
59 changes: 59 additions & 0 deletions solutions/multiplehubs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Multiplehubs

In this demo, we are going to use 3 clusters: `hub1`, `hub2` and `agent` to show the MultipleHubs feature.

We will enable MultipleHubs feature on the managedcluster, the agent will first be registered to hub1.

Then we will trigger the managedcluster to switch to hub2 by manually by setting the ManagedCluster `hubAcceptsClient` to false on hub1.

After that, we will observe that the managedcluster will automatically register to hub2.

Next, We set the ManagedCluster `hubAcceptsClient` to true on hub1 and delete the hub2, we will observe that the managedcluster will automatically register back to hub1 and be available.

## Prerequisites

Run the following command to install the prerequisites:

```bash
sh setup.sh
```

## Switch agent to hub2

Run the following command to switch the managedcluster to hub2, first set the ManagedCluster `hubAcceptsClient` to false on hub1, then watch the managedcluster to be unaccepted from hub1:

```bash
kubectl --context kind-hub1 patch managedcluster agent --type=merge -p '{"spec":{"hubAcceptsClient":false}}'
kubectl --context kind-hub1 get managedcluster -w
```

Wait for the managedcluster to be `Available` on hub2:

```bash
kubectl --context kind-hub2 get managedcluster -w
```

## Switch agent to hub1

Set the ManagedCluster `hubAcceptsClient` back to true on hub1:
```bash
kubectl --context kind-hub1 patch managedcluster agent --type=merge -p '{"spec":{"hubAcceptsClient":true}}'
```

It takes about 5 minutes for the managedcluster to be updated to `Unknown` on hub1:

```bash
kubectl --context kind-hub1 get managedcluster -w
```

Delete the hub2:

```bash
kind delete cluster --name hub2
```

After 5 minutes, the managedcluster to be switched back to hub1 and be `Available`:

```bash
kubectl --context kind-hub1 get managedcluster -w
```
40 changes: 40 additions & 0 deletions solutions/multiplehubs/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# In this demo, we are going to use 3 clusters: hub1, hub2 and agent.
#
# We will enable MultipleHubs feature on agent, the agent will first be registered to hub1.
# Then we manually reject the registration from agent on hub1 by setting the managed cluster `hubAcceptsClient` to false.
# After that, we will observe that the agent will automatically register to hub2.
# Next, We set the managed cluster `hubAcceptsClient` to true on hub1 and delete the hub2, we will observe that the agent will automatically register back to hub1.

kind create cluster --name hub1
kind create cluster --name hub2
kind create cluster --name agent

# Init the hub1
clusteradm init --wait --bundle-version=latest --context kind-hub1
joinhub1=$(clusteradm get token --context kind-hub1 | grep clusteradm)

# Join the agent into the hub1
$(echo ${joinhub1} --bundle-version=latest --force-internal-endpoint-lookup --wait --context kind-agent | sed "s/<cluster_name>/agent/g")
clusteradm accept --context kind-hub1 --clusters agent --wait

# Init the hub2
clusteradm init --wait --bundle-version=latest --context kind-hub2

# Prepare the hub1, hub2 bootstrap kubeconfigs
kind get kubeconfig --name hub1 --internal > hub1.kubeconfig
kind get kubeconfig --name hub2 --internal > hub2.kubeconfig

# Save hub1, hub2 bootstrap kubeconfigs as secrets in the open-cluster-management-agent ns
kubectl --context kind-agent create secret generic hub1-kubeconfig -n open-cluster-management-agent --from-file=kubeconfig=hub1.kubeconfig
kubectl --context kind-agent create secret generic hub2-kubeconfig -n open-cluster-management-agent --from-file=kubeconfig=hub2.kubeconfig

# Enable AutoApproval on hub1, hub2
# The username is kubernetes-admin, which is the default admin user in kind clusters
kubectl --context kind-hub1 patch clustermanager cluster-manager --type=merge -p '{"spec":{"registrationConfiguration":{"featureGates":[
{"feature": "ManagedClusterAutoApproval", "mode": "Enable"}], "autoApproveUsers":["kubernetes-admin"]}}}'
kubectl --context kind-hub2 patch clustermanager cluster-manager --type=merge -p '{"spec":{"registrationConfiguration":{"featureGates":[
{"feature": "ManagedClusterAutoApproval", "mode": "Enable"}], "autoApproveUsers":["kubernetes-admin"]}}}'

# Enable MultipleHubs feature on agent
kubectl --context kind-agent patch klusterlet klusterlet --type=merge -p '{"spec":{"registrationConfiguration":{"featureGates":[
{"feature": "MultipleHubs", "mode": "Enable"}], "bootstrapKubeConfigs":{"type":"LocalSecrets", "localSecretsConfig":{"hubConnectionTimeoutSeconds":180,"kubeConfigSecrets":[{"name":"hub1-kubeconfig"},{"name":"hub2-kubeconfig"}]}}}}}'

0 comments on commit 233c61b

Please sign in to comment.