Skip to content

Instantly share code, notes, and snippets.

@der-ali
Last active June 26, 2023 09:35
Show Gist options
  • Save der-ali/59e7f64ed52a726958125a2d64419156 to your computer and use it in GitHub Desktop.
Save der-ali/59e7f64ed52a726958125a2d64419156 to your computer and use it in GitHub Desktop.
Open cluster management (OCP) demo on minikube
#!/bin/bash -
#===============================================================================
#
# FILE: ocp-demo.sh
#
# USAGE: ./ocp-demo.sh
#
# DESCRIPTION: setup a hub cluster and 2 managed clusters on minikube
#
# OPTIONS: ---
# REQUIREMENTS: clusteradm cli: https://github.com/open-cluster-management-io/clusteradm
# CREATED: 06/26/2023 11:26
#===============================================================================
set -e
if ! command -v kubectl &> /dev/null; then
echo "Error: kubectl is not installed. Please make sure kubectl is installed."
exit 1
fi
if ! command -v clusteradm &> /dev/null; then
echo "Error: clusteradm is not installed. Please make sure clusteradm is installed."
exit 1
fi
cd $(dirname ${BASH_SOURCE})
hub="hub"
c1="cluster1"
c2="cluster2"
minikube start -p ${hub} --kubernetes-version=1.22.0 --container-runtime=containerd --nodes 1 --memory 2048 --cpus 2 --network=ocm-demo
minikube start -p ${c1} --kubernetes-version=1.22.0 --container-runtime=containerd --nodes 2 --memory 2048 --cpus 2 --network=ocm-demo
minikube start -p ${c2} --kubernetes-version=1.22.0 --container-runtime=containerd --nodes 2 --memory 2048 --cpus 2 --network=ocm-demo
echo "Initialize the ocm hub cluster\n"
clusteradm init --wait --context ${hub}
joincmd=$(clusteradm get token --context ${hub} | grep clusteradm)
echo "Join cluster1 to hub\n"
$(echo ${joincmd} --wait --context ${c1} | sed "s/<cluster_name>/$c1/g")
echo "Join cluster2 to hub\n"
$(echo ${joincmd} --wait --context ${c2} | sed "s/<cluster_name>/$c2/g")
echo "Accept join of cluster1 and cluster2"
clusteradm accept --context ${hub} --clusters ${c1},${c2} --wait
kubectl get managedclusters --all-namespaces --context ${hub}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment