Created
May 27, 2022 12:54
-
-
Save mundra-ankur/15c3d93435949f9ca42aa5f31a1edbc9 to your computer and use it in GitHub Desktop.
IBM Cloud: Launch VPC Gen2 Openshift Cluster Using CLI
This file contains hidden or 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
#!/bin/bash | |
echo -e "Launch Openshift Cluster in IBM Cloud using CLI \n\n" | |
# Installing the IBM Cloud CLI | |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh | |
ibmcloud update | |
ibmcloud -v | |
echo -e "-------------------------------------------------------------\n" | |
# Install the IBM Cloud plug-in for IBM Cloud Kubernetes Service | |
echo 'Installing plug-in for Kubernetes Service, Container Registry, Kubernetes Service observability, and VPC infrastructure service' | |
ibmcloud plugin install container-service -N | |
ibmcloud plugin install container-registry -N | |
ibmcloud plugin install observe-service -N | |
ibmcloud plugin install vpc-infrastructure | |
ibmcloud plugin update | |
ibmcloud plugin list | |
echo -e '-------------------------------------------------------------\n' | |
# Log in to the IBM Cloud CLI. Enter your IBM Cloud credentials when prompted. | |
echo 'Login to IBM Cloud CLI' | |
ibmcloud login --sso | |
echo -e '-------------------------------------------------------------\n' | |
# List all resource groups under the currently targeted account: | |
ibmcloud resource groups | |
# Set the target resource group | |
read -p "From the above output, enter the target resource group name: " resource_group | |
ibmcloud target -g $resource_group | |
echo -e '-------------------------------------------------------------\n' | |
## Using the CLI to create VPC resources | |
echo 'Selecting the target generation 2 virtual server instances for VPC' | |
ibmcloud is target --gen 2 | |
echo -e '-------------------------------------------------------------\n' | |
## Create a VPC | |
echo 'Creating VPC...' | |
read -p "Enter name of VPC to be created: " vpc_name | |
vpc=$(ibmcloud is vpc-create "$vpc_name" --output json | jq -r .id) | |
echo -e '-------------------------------------------------------------\n' | |
## Create a subnet | |
echo 'Creating subnet...' | |
read -p 'Enter name of subnet to be created: ' subnet_name | |
# List the address prefixes for each zone in your VPC | |
ibmcloud is vpc-address-prefixes $vpc | |
echo -e '\nFrom the above command output' | |
read -p 'Enter the selected zone: ' zone | |
read -p "Enter the CIDR block of the address prefix for your target $zone region: " cidr | |
echo | |
subnet=$(ibmcloud is subnet-create $subnet_name $vpc $zone --ipv4-cidr-block $cidr --output json | jq -r .id) | |
echo -e '-------------------------------------------------------------\n' | |
## Attach a public gateway to subnet | |
# Create a public gateway | |
echo "Creating a public gateway..." | |
read -p "Enter name of gateway to be created: " gateway_name | |
gateway=$(ibmcloud is public-gateway-create $gateway_name $vpc $zone --output json | jq -r .id) | |
echo -e '\nAttaching the public gateway to your subnet' | |
ibmcloud is subnet-update $subnet --pgw $gateway | |
echo -e '-------------------------------------------------------------\n' | |
## Create a COS resource - to backup the internal registry of your cluster | |
echo 'Creating COS resource...' | |
read -p "Enter name of Cloud Object Storage(COS) instance to be created: " cos_name | |
ibmcloud resource service-instance-create $cos_name cloud-object-storage standard global | |
read -p "From the output that's returned, enter the cos crn(ID): " cos_crn | |
echo -e '-------------------------------------------------------------\n' | |
## Create Openshift Cluster | |
echo "Creating openshift cluster..." | |
ibmcloud ks flavors --zone "$zone" | |
echo -e "\nRecommended, flavor with 4 cores and 16GB memory, i.e. bx2.4x16" | |
read -p "Select the flavor for your cluster: " flavor | |
read -p "Enter name of the cluster to be created: " cluster_name | |
read -p "Provide the openshift version: " openshift_version | |
read -p "Enter the number of worker nodes (for each zone): " worker | |
ibmcloud oc cluster create vpc-gen2 --name $cluster_name --version "$openshift_version"_openshift --zone $zone --vpc-id $vpc --subnet-id $subnet --cos-instance $cos_crn --flavor $flavor --workers $worker | |
echo -e "\n\nCluster successfully created!" | |
echo "Check the status of your cluster at https://cloud.ibm.com/kubernetes/clusters" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script to launch openshift cluster in IBM
IBM Cloud: Launch VPC Gen2 Openshift Cluster