-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multiplehubs solution and rename multiple-agents-hosted to multip…
…le-agents (#626) Signed-off-by: xuezhaojun <[email protected]>
- Loading branch information
1 parent
7772622
commit 233c61b
Showing
6 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
solutions/multiple-hubs-hosted/README.md → solutions/multiple-agents-hosted/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}]}}}}}' |