In this guide we will deploy a testing microk8s cluster in to an IBM Cloud VPC ☁️. MicroK8s allows you to deploy fully functional, highly available Kubernetes clusters on a wide variety of infrastructure and platforms. With the ability to quickly toggle features on and off, microk8s is a great tool for testing and learning Kubernetes.
In this guide we will be using Terraform to provision the VPC infrastructure and Ansible to handle the post provisioning configuration of the the cluster.
This guide is written to utilize IBM Cloud Shell as the development environment. Cloud Shell is a free, browser-based shell environment that includes Terraform, Ansible, and the IBM Cloud CLI. If you prefer to use your own environment, see the Local Prerequisites section below to ensure you have all the required software installed.
To deploy our microk8s cluster, you will need to ensure you have the following prerequisites:
-
IBM Cloud API Key. See here for instructions on how to create one via the Portal. Alternately you can use the following CLI command to create one:
ibmcloud iam api-key-create "$(whoami)-microk8s-vpc-apikey" -d "API key for microk8s deployment" --file "$(whoami)-microk8s-vpc-apikey.json"
-
Recent version of Terraform installed. This guide was tested on
terraform 1.5.3
. -
A recent version of Ansible installed. This guide was tested on
ansible 2.15.2
. -
(Optional)
- tfswitch installed. Thetfswitch
utility allows you to run multiple versions of Terraform on the same system. If you do not have a particular version of terraform installed, tfswitch will download the version you select from an interactive menu.
With the prerequisites installed and up to date, you can start deploying the cluster.
-
Clone this repo and
cd
into themicrok8s-ibmcloud-vpc
directory.git clone https://github.com/cloud-design-dev/microk8s-ibmcloud-vpc.git cd microk8s-ibmcloud-vpc
-
Copy the
tfvars-example
toterraform.tfvars
file and update the values as needed. See here for full list of variables.:cp tfvars-example terraform.tfvars
-
Initialize Terraform:
terraform init -upgrade
-
Run a Terraform plan:
terraform plan -out "$(terraform workspace show).tfplan"
-
Run Terraform apply:
terraform apply "$(terraform workspace show).tfplan"
Once the cluster is deployed, you should see some output about your deployed infrastructure, as well as the commands for running the Ansible playbooks.
Apply complete! Resources: 25 added, 0 changed, 0 destroyed.
Outputs:
bastion_ip = "<your bastion ip>"
step_01_ping_hosts = "ansible-playbook -i ansible/inventory.ini ansible/playbooks/ping-all.yml"
step_02_update_hosts = "ansible-playbook -i ansible/inventory.ini ansible/playbooks/update-systems.yml"
step_03_deploy_cluster = "ansible-playbook -i ansible/inventory.ini ansible/playbooks/configure-microk8s.yml"
-
Run the
ping-all.yml
playbook to ensure all hosts are reachable:ansible-playbook -i ansible/inventory.ini ansible/playbooks/ping-all.yml
-
Run the
update-systems.yml
playbook to update the hosts and insure required packages are installed:ansible-playbook -i ansible/inventory.ini ansible/playbooks/update-systems.yml
-
Finally, run the
configure-microk8s.yml
playbook to configure our microk8s cluster:ansible-playbook -i ansible/inventory.ini ansible/playbooks/configure-microk8s.yml
When the configure-microk8s.yml
playbook completes, you can run the following command to get the clusters compute nodes:
ansible -m shell -b -a "microk8s kubectl get nodes" CONTROL_PLANE_NODE -i ansible/inventory.ini
If everything went as planned you should see output similar to the following:
[$] <git:(main*)> ansible -m shell -b -a "microk8s kubectl get nodes" qywx-controller-1 -i ansible/inventory.ini
qywx-controller-1 | CHANGED | rc=0 >>
NAME STATUS ROLES AGE VERSION
qywx-worker-1 Ready worker 7m5s v1.27.2
qywx-worker-3 Ready worker 7m4s v1.27.2
qywx-worker-2 Ready worker 7m3s v1.27.2
qywx-controller-1 Ready contoller 11m v1.27.2
This repository comes with a devcontainer
configuration file. If you would like to use this containerized development environment, ensure you have the following installed:
To reopen this repository in the development container, open the command pallete on VS Code and select Rebuild and Reopen in Container