mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 18:09:57 +00:00
📖 add solutions of multiple hubs (#304)
Signed-off-by: Yang Le <yangle@redhat.com>
This commit is contained in:
91
solutions/multiple-hubs-hosted/README.md
Normal file
91
solutions/multiple-hubs-hosted/README.md
Normal file
@@ -0,0 +1,91 @@
|
||||
# Manage a cluster with multiple hubs 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.
|
||||
|
||||
## Prerequisite
|
||||
|
||||
- [kind](https://kind.sigs.k8s.io) must be installed on your local machine. The Kubernetes version must be >= 1.19, see [kind user guide](https://kind.sigs.k8s.io/docs/user/quick-start/#creating-a-cluster) for more details.
|
||||
|
||||
- Download and install [clusteradm](https://github.com/open-cluster-management-io/clusteradm/releases). For Linux OS, run the following commands:
|
||||
|
||||
```
|
||||
wget -qO- https://github.com/open-cluster-management-io/clusteradm/releases/latest/download/clusteradm_linux_amd64.tar.gz | sudo tar -xvz -C /usr/local/bin/
|
||||
|
||||
sudo chmod +x /usr/local/bin/clusteradm
|
||||
```
|
||||
|
||||
## Setup the first hub cluster
|
||||
|
||||
Run `./setup-hub1.sh`. It creates two kind clusters:
|
||||
- `hub1`. It is initialized as a OCM hub cluster.
|
||||
- `cluster1`. It joins the `hub1` as a managed cluster in the default mode.<br/>
|
||||
|
||||
Once it is done, you can then list the managed clusters on `hub1` with command below.
|
||||
```bash
|
||||
kubectl get managedclusters
|
||||
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
|
||||
cluster1 true https://cluster1-control-plane:6443 29s
|
||||
```
|
||||
The managed cluster `cluster1` joins `hub1` in the default mode and its Klusterlet resource is created on the managed cluster.
|
||||
```bash
|
||||
kubectl get klusterlet
|
||||
NAME AGE
|
||||
klusterlet 1m
|
||||
```
|
||||
And the OCM agent of `hub1` is installed under namespace `open-cluster-management-agent` on the managed cluster. Another namespace `open-cluster-management-agent-addon` is created too for add-ons which might be installed in future for this managed cluster.
|
||||
```bash
|
||||
kubectl get ns
|
||||
NAME STATUS AGE
|
||||
default Active 7m34s
|
||||
kube-node-lease Active 7m34s
|
||||
kube-public Active 7m34s
|
||||
kube-system Active 7m34s
|
||||
local-path-storage Active 7m30s
|
||||
open-cluster-management Active 7m27s
|
||||
open-cluster-management-agent Active 7m27s
|
||||
open-cluster-management-agent-addon Active 7m11s
|
||||
```
|
||||
## Setup the second hub cluster
|
||||
Run `./setup-hub2.sh`. It creates two more Kind clusters:
|
||||
- `hub2`. It is initialized as the second OCM hub cluster.
|
||||
- `hosting`. It is used as the hosting cluster on which the OCM agent of `hub2` is running.
|
||||
|
||||
The script also joins the previously created Kind cluster `cluster1` to `hub2` as a managed cluster in the hosted mode. Once it is done, you can list the managed clusters on `hub2` with command below.
|
||||
```bash
|
||||
kubectl get managedclusters
|
||||
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
|
||||
cluster1 true https://cluster1-control-plane:6443 True True 38s
|
||||
```
|
||||
Since the managed cluster `cluster1` joins in the hosted mode, its Klusterlet resource is created on the hosting cluster instead of the managed cluster.
|
||||
```bash
|
||||
kubectl get klusterlet
|
||||
NAME AGE
|
||||
klusterlet-hosted-cuz6ia 53s
|
||||
```
|
||||
The OCM agent of `hub2` is installed under namespace `klusterlet-hosted-cuz6ia` on the hosting cluster as well.
|
||||
```bash
|
||||
kubectl get ns
|
||||
NAME STATUS AGE
|
||||
default Active 77s
|
||||
klusterlet-hosted-cuz6ia Active 57s
|
||||
kube-node-lease Active 77s
|
||||
kube-public Active 77s
|
||||
kube-system Active 77s
|
||||
local-path-storage Active 72s
|
||||
open-cluster-management Active 57s
|
||||
```
|
||||
Some namespaces, like `open-cluster-management-klusterlet-hosted-cuz6ia` and `open-cluster-management-klusterlet-hosted-cuz6ia-addon`, are created on the managed cluster `cluster1` which are required by the OCM agent of `hub2` running in the hosted mode.
|
||||
```bash
|
||||
kubectl get ns
|
||||
NAME STATUS AGE
|
||||
default Active 4m25s
|
||||
kube-node-lease Active 4m25s
|
||||
kube-public Active 4m25s
|
||||
kube-system Active 4m25s
|
||||
local-path-storage Active 4m21s
|
||||
open-cluster-management Active 4m12s
|
||||
open-cluster-management-agent Active 4m12s
|
||||
open-cluster-management-agent-addon Active 4m3s
|
||||
open-cluster-management-klusterlet-hosted-cuz6ia Active 78s
|
||||
open-cluster-management-klusterlet-hosted-cuz6ia-addon Active 78s
|
||||
```
|
||||
26
solutions/multiple-hubs-hosted/setup-hub1.sh
Executable file
26
solutions/multiple-hubs-hosted/setup-hub1.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
hub=${HUB_NAME:-hub1}
|
||||
cluster=${CLUSTER_NAME:-cluster1}
|
||||
|
||||
hubctx="kind-${hub}"
|
||||
clusterctx="kind-${cluster}"
|
||||
|
||||
kind create cluster --name "${hub}"
|
||||
kind create cluster --name "${cluster}"
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Initialize the ocm hub cluster"
|
||||
joincmd=$(clusteradm init --use-bootstrap-token | grep clusteradm)
|
||||
kubectl wait --for=condition=HubRegistrationDegraded=false clustermanager cluster-manager --timeout=60s
|
||||
|
||||
kubectl config use ${clusterctx}
|
||||
echo "Join ${cluster} to ${hub}"
|
||||
$(echo ${joincmd} --singleton --force-internal-endpoint-lookup --wait | sed "s/<cluster_name>/$cluster/g")
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Accept join of ${cluster} on ${hub}"
|
||||
clusteradm accept --clusters ${cluster} --wait
|
||||
|
||||
kubectl get managedclusters
|
||||
32
solutions/multiple-hubs-hosted/setup-hub2.sh
Executable file
32
solutions/multiple-hubs-hosted/setup-hub2.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
hub=${HUB_NAME:-hub2}
|
||||
hosting=${HOSTING_CLUSTER_NAME:-hosting}
|
||||
cluster=${CLUSTER_NAME:-cluster1}
|
||||
|
||||
hubctx="kind-${hub}"
|
||||
hostingctx="kind-${hosting}"
|
||||
clusterctx="kind-${cluster}"
|
||||
|
||||
kind create cluster --name "${hub}"
|
||||
kind create cluster --name "${hosting}"
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Initialize the ocm hub cluster"
|
||||
joincmd=$(clusteradm init --use-bootstrap-token | grep clusteradm)
|
||||
kubectl wait --for=condition=HubRegistrationDegraded=false clustermanager cluster-manager --timeout=60s
|
||||
|
||||
kubectl config use ${clusterctx}
|
||||
kubectl config view --flatten --minify | sed "s/127.0.0.1:[0-9]\{5\}/${cluster}-control-plane:6443/" > kubeconfig.${cluster}
|
||||
|
||||
kubectl config use ${hostingctx}
|
||||
echo "Join ${cluster} to ${hub}"
|
||||
$(echo ${joincmd} --singleton --force-internal-endpoint-lookup --mode hosted --managed-cluster-kubeconfig kubeconfig.${cluster} --wait | sed "s/<cluster_name>/$cluster/g")
|
||||
rm kubeconfig.${cluster}
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Accept join of ${cluster} on ${hub}"
|
||||
clusteradm accept --clusters ${cluster} --wait
|
||||
|
||||
kubectl get managedclusters
|
||||
76
solutions/multiple-hubs/README.md
Normal file
76
solutions/multiple-hubs/README.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Manage a cluster with multiple hubs
|
||||
|
||||
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 thoes two hubs are all running in the default mode on the managed cluster under different namespaces.
|
||||
|
||||
## Prerequisite
|
||||
|
||||
- [kind](https://kind.sigs.k8s.io) must be installed on your local machine. The Kubernetes version must be >= 1.19, see [kind user guide](https://kind.sigs.k8s.io/docs/user/quick-start/#creating-a-cluster) for more details.
|
||||
|
||||
- Download and install [clusteradm](https://github.com/open-cluster-management-io/clusteradm/releases). For Linux OS, run the following commands:
|
||||
|
||||
```
|
||||
wget -qO- https://github.com/open-cluster-management-io/clusteradm/releases/latest/download/clusteradm_linux_amd64.tar.gz | sudo tar -xvz -C /usr/local/bin/
|
||||
|
||||
sudo chmod +x /usr/local/bin/clusteradm
|
||||
```
|
||||
|
||||
## Setup the first hub cluster
|
||||
|
||||
Run `./setup-hub1.sh`. It creates two Kind clusters:
|
||||
- `hub1`. It is initialized as a OCM hub cluster.
|
||||
- `cluster1`. It joins the `hub1` as a managed cluster.<br/>
|
||||
|
||||
Once it is done, you can then list the managed clusters on `hub1` with command below.
|
||||
```bash
|
||||
kubectl get managedclusters
|
||||
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
|
||||
cluster1 true https://cluster1-control-plane:6443 29s
|
||||
```
|
||||
The managed cluster `cluster1` joins `hub1` in the default mode and its Klusterlet resource is created on the managed cluster.
|
||||
```bash
|
||||
kubectl get klusterlet
|
||||
NAME AGE
|
||||
klusterlet 58s
|
||||
```
|
||||
And the OCM agent of `hub1` is installed under namespace `open-cluster-management-agent` on the managed cluster. Another namespace `open-cluster-management-agent-addon` is created too for add-ons which might be installed in future for this managed cluster.
|
||||
```bash
|
||||
kubectl get ns
|
||||
NAME STATUS AGE
|
||||
default Active 7m34s
|
||||
kube-node-lease Active 7m34s
|
||||
kube-public Active 7m34s
|
||||
kube-system Active 7m34s
|
||||
local-path-storage Active 7m30s
|
||||
open-cluster-management Active 7m27s
|
||||
open-cluster-management-agent Active 7m27s
|
||||
open-cluster-management-agent-addon Active 7m11s
|
||||
```
|
||||
## Setup the second hub cluster
|
||||
Run `./setup-hub2.sh` to create one more Kind cluster `hub2` and initialize it as the second OCM hub cluster. The script also joins the previously created Kind cluster `cluster1` to `hub2` as a managed cluster as well. Once it is done, you can list the managed clusters on `hub2` with command below.
|
||||
```bash
|
||||
kubectl get managedclusters
|
||||
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
|
||||
cluster1 true https://cluster1-control-plane:6443 True True 30s
|
||||
```
|
||||
The managed cluster `cluster1` joins `hub2` in the default mode and its Klusterlet resource `klusterlet-hub2` is created on the managed cluster as well.
|
||||
```bash
|
||||
kubectl get klusterlet
|
||||
NAME AGE
|
||||
klusterlet 16m
|
||||
klusterlet-hub2 1m
|
||||
```
|
||||
And the OCM agent of `hub2` is installed under `open-cluster-management-agent-hub2` on the managed cluster.
|
||||
```bash
|
||||
kubectl get ns
|
||||
NAME STATUS AGE
|
||||
default Active 19m
|
||||
kube-node-lease Active 19m
|
||||
kube-public Active 19m
|
||||
kube-system Active 19m
|
||||
local-path-storage Active 18m
|
||||
open-cluster-management Active 18m
|
||||
open-cluster-management-agent Active 18m
|
||||
open-cluster-management-agent-addon Active 18m
|
||||
open-cluster-management-agent-hub2 Active 105s
|
||||
open-cluster-management-agent-hub2-addon Active 105s
|
||||
```
|
||||
26
solutions/multiple-hubs/setup-hub1.sh
Executable file
26
solutions/multiple-hubs/setup-hub1.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
hub=${HUB_NAME:-hub1}
|
||||
cluster=${CLUSTER_NAME:-cluster1}
|
||||
|
||||
hubctx="kind-${hub}"
|
||||
clusterctx="kind-${cluster}"
|
||||
|
||||
kind create cluster --name "${hub}"
|
||||
kind create cluster --name "${cluster}"
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Initialize the ocm hub cluster"
|
||||
joincmd=$(clusteradm init --use-bootstrap-token | grep clusteradm)
|
||||
kubectl wait --for=condition=HubRegistrationDegraded=false clustermanager cluster-manager --timeout=60s
|
||||
|
||||
kubectl config use ${clusterctx}
|
||||
echo "Join ${cluster} to ${hub}"
|
||||
$(echo ${joincmd} --singleton --force-internal-endpoint-lookup --wait | sed "s/<cluster_name>/$cluster/g")
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Accept join of ${cluster} on ${hub}"
|
||||
clusteradm accept --clusters ${cluster} --wait
|
||||
|
||||
kubectl get managedclusters
|
||||
28
solutions/multiple-hubs/setup-hub2.sh
Executable file
28
solutions/multiple-hubs/setup-hub2.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
hub=${HUB_NAME:-hub2}
|
||||
cluster=${CLUSTER_NAME:-cluster1}
|
||||
|
||||
hubctx="kind-${hub}"
|
||||
clusterctx="kind-${cluster}"
|
||||
|
||||
kind create cluster --name "${hub}"
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Initialize the ocm hub cluster"
|
||||
joincmd=$(clusteradm init --use-bootstrap-token | grep clusteradm)
|
||||
kubectl wait --for=condition=HubRegistrationDegraded=false clustermanager cluster-manager --timeout=60s
|
||||
|
||||
kubectl config use ${clusterctx}
|
||||
echo "Join ${cluster} to ${hub}"
|
||||
$(echo ${joincmd} --singleton --force-internal-endpoint-lookup --dry-run --output-file import.yaml | sed "s/<cluster_name>/$cluster/g")
|
||||
kubectl create ns "open-cluster-management-agent-$hub"
|
||||
cat import.yaml | sed "s/open-cluster-management-agent/open-cluster-management-agent-$hub/g" | sed "s/name: klusterlet/name: klusterlet-$hub/g" | kubectl apply -f -
|
||||
rm import.yaml
|
||||
|
||||
kubectl config use ${hubctx}
|
||||
echo "Accept join of ${cluster} on ${hub}"
|
||||
clusteradm accept --clusters ${cluster} --wait
|
||||
|
||||
kubectl get managedclusters
|
||||
Reference in New Issue
Block a user