Use Terraform to create a VPC and a Kubernetes Cluster on IBM Cloud

This blog post contains a simple example to create a Virtual Private Cloud and a Kubernetes Cluster on IBM Cloud using Terraform. The example is based on following resources:

You can find a GitHub project with all the source code for Terraform and a bash automation here.

The blog post is structured in following sections:

  • Simplified architecture overview
  • Terraform variables overview
  • Prerequisites (for an automated bash setup)
  • Step by step example setup
  • Summary

Simplified architecture of overview

Here you can get an overview of the simplified architecture and the resources which will be created/configured on IBM Cloud:

Terraform variables overview

NameDescriptionTypeDefault Value
flavorDefault worker node flaver. Use ‘ibmcloud ks flavors –zone us-south-1’ to verify the availability.Stringbx2.4×16
worker_countDefault worker node count is set to 2.Integer2
resource_groupIBM Cloud resource group name.Stringdefault
vpc_nameThe Virtual Private Cloud name.Stringoperator-sample
regionIBM Cloud region for the Kubernetes Cluster and the VPCStringus-south
kube_versionThe tested Kubernetes Cluster version for the example is 1.23.8.String1.23.8
cluster_nameKubernetes Cluster Name running in VPC Gen2.Stringoperator-sample-ks-cluster
kubernetes_pricingKubernetes Cluster pricing.Stringtiered-pricing

Note: IBM Cloud on the Terraform registry.

Prerequisites for a local setup

To use an example bash automation following tools need to be installed on the local computer

  • IBM Cloud CLI
    • Plugin VPC infrastructure
    • Plugin Container-service
  • Terraform

Example setup

Here are the steps to use Terraform locally with a bash automation, but you can also use Schematics on IBM Cloud for the setup. Here is an older blog post I wrote which does cover an example how to use Schematics for creating a Red Hat OpenShift cluster. Just follow this link.

Step 1: Clone the repo

git clone https://github.com/thomassuedbroecker/terraform-vpc-kubernetes.git
cd terraform-vpc-kubernetes

Step 2: Verify the configuration of the variables.tf file

nano variables.tf

Step 3: Create a variables.env file

cat variables_template.env > variables.env

Step 4: Add an IBM Cloud access key to your local variables.env file

nano variables.env

Content of the file:

export IC_API_KEY=YOUR_IBM_CLOUD_ACCESS_KEY
export TF_LOG=debug
export REGION="us-south"
export GROUP="default"

Step 5: Execute the bash automation

Execute the create_vpc_kubernetes_cluster_with_terraform.sh bash script. The creation can take up to 2 hours, depending on the which region you are using and where you are located.

sh create_vpc_kubernetes_cluster_with_terraform.sh

Summary

I like using Terraform for infrastructure as code locally on my machine or using it with Schematics on IBM Cloud. With Schematics you have an easy overview of your created resources and you can directly navigate to you resources, update your resources or delete your resources. In the following image you see the resources created by the Terraform example when I was using Schematics:

There is a lot of useful documentation out there, so that you can achieve very fast an implementation with Terraform. In my case I used as a starting point these three very useful links:


I hope this was useful to you and let’s see what’s next?

Greetings,

Thomas

#ibmcloud, #vpc, #schematics, #terraform, #kubernetes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.