Add setup envrionment (#5)

Signed-off-by: Jian Qiu <jqiu@redhat.com>
This commit is contained in:
Jian Qiu
2021-10-25 21:48:51 +08:00
committed by GitHub
parent 6a9d3f67b3
commit 25e4c01ca3
3 changed files with 60 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ You can use the [clusteradm CLI](https://github.com/open-cluster-management-io/c
![image](assets/ocm-arch.png)
To setup a multicluster environment with OCM enabled on your local machine, follow the instructions in [setup dev environment](solutions/setup-dev-environment).
There are a number of key use cases that are enabled by this project, and are categorized to 3 sub projects.
### Cluster Lifecycle: Cluster registration and management

View File

@@ -0,0 +1,25 @@
# Setup dev environment by kind
This scripts is to setup an OCM developer environment in your local machine with 3 kind clusters. The script will bootstrap 3 kind clusters on your local machine: hub, cluster1, and cluster2. The hub is used as the control plane of the OCM, and the other two clusters are registered on the hub as the managed clusters.
## 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 clusters
Run `./local-up.sh`, you will see two clusters registered on the hub cluster.
```
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE
cluster1 true https://127.0.0.1:45325 True True 116s
cluster2 true https://127.0.0.1:45325 True True 98s
```

View File

@@ -0,0 +1,33 @@
#!/bin/bash
cd $(dirname ${BASH_SOURCE})
set -e
hub=${CLUSTER1:-hub}
c1=${CLUSTER1:-cluster1}
c2=${CLUSTER2:-cluster2}
hubctx="kind-${hub}"
c1ctx="kind-${c1}"
c2ctx="kind-${c2}"
kind create cluster --name "${hub}"
kind create cluster --name "${c1}"
kind create cluster --name "${c2}"
kubectl config use ${hubctx}
echo "Initialize the ocm hub cluster"
joincmd=$(clusteradm init --use-bootstrap-token | grep clusteradm)
kubectl config use ${c1ctx}
echo "Join cluster1 to hub"
$(echo ${joincmd} | sed "s/<cluster_name>/$c1/g")
kubectl config use ${c2ctx}
echo "Join cluster2 to hub"
$(echo ${joincmd} | sed "s/<cluster_name>/$c2/g")
kubectl config use ${hubctx}
echo "Accept join of cluster1 and cluster2"
clusteradm accept --clusters ${c1},${c2}