Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cluster-api solution #78

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions solutions/cluster-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Working with the Cluster API project

[Cluster API](https://cluster-api.sigs.k8s.io/) is a Kubernetes sub-project focused on providing declarative APIs and
tooling to simplify provisioning, upgrading, and operating multiple Kubernetes clusters. This doc is a guideline on how
to use the Cluster API project and the [Open Cluster Management (OCM)](https://open-cluster-management.io/) project together.

## Prerequisite
Download and install [clusteradm](https://github.com/open-cluster-management-io/clusteradm/releases). For Linux OS, run the following commands:

```shell
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
```

Follow the instruction [here](https://cluster-api.sigs.k8s.io/user/quick-start.html) to install the `clusterctl`.

## Initialize the Cluster API management plane and create a cluster

Before initilize the management plane, some feature gates should be enabled:

```shell
export CLUSTER_TOPOLOGY=true
export EXP_CLUSTER_RESOURCE_SET=true
```

Next initiate the Cluster API management plane by following [this](https://cluster-api.sigs.k8s.io/user/quick-start.html#initialize-the-management-cluster)

Now create a cluster on any cloud provider by following the instruction [here](https://cluster-api.sigs.k8s.io/user/quick-start.html#create-your-first-workload-cluster).

## Initialize the OCM multicluster control plane hub cluster and register the newly created cluster

The OCM multicluster control plane hub can be run in the same cluster as the Cluster API management plane. Use the following command to initialize the hub cluster:

```
clusteradm init --use-bootstrap-token
```

Register the newly created cluster by running the following command:

```
./register-join.sh <cluster-name> # ./register-join.sh capi-cluster
```

qiujian16 marked this conversation as resolved.
Show resolved Hide resolved
The registration process might take a while. After it's done, you can run the following command to verify the newly created cluster has successfully joined the hub cluster:

```
kubectl get managedcluster
```
29 changes: 29 additions & 0 deletions solutions/cluster-api/register-join.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

cd $(dirname ${BASH_SOURCE})

set -e

CLUSTER_NAME=$1

echo "get bootstrap token from ocm hub cluster"
joincmd=$(clusteradm get token --use-bootstrap-token | grep clusteradm)

echo "Join $1 to hub"
$(echo ${joincmd} --dry-run --output-file join.yaml | sed "s/<cluster_name>/$CLUSTER_NAME/g")
kubectl create secret generic import-secret-$1 --from-file=join.yaml --type=addons.cluster.x-k8s.io/resource-set

cat << EOF | kubectl apply -f -
apiVersion: addons.cluster.x-k8s.io/v1alpha3
kind: ClusterResourceSet
metadata:
name: import-$CLUSTER_NAME
spec:
strategy: "ApplyOnce"
clusterSelector:
matchLabels:
cluster.x-k8s.io/cluster-name: $CLUSTER_NAME
resources:
- name: import-secret
kind: Secret
EOF