Kubernetes Cluster - Automatic Provisioning with Vagrant & Containerd

products versions - {Ubuntu 22.04, Kubernetes 1.24.00 }

Introduction

This article will guide you through the steps to create a Kubernetes cluster setup with Master + Worker nodes on Oracle Virtual Box.

Pre-requisite

Please make sure to have the below mentioned pre-requisite setup completed before starting with this.

  1. Install Oracle Virtual Box manager.
  2. Install Vagrant.
  3. Copy the attached files, unzip it and place it in some folder in the system.
  4. Hypervisor should be disabled (because this interferes with Oracle Virtual Box).
    Disable Hyper-V to run virtualization software - Windows Client | Microsoft Learn

Configurations

This set-up is fully automated and controlled via configurations from properties file.
Some important configurations which can be altered as per needs are mentioned below.

  1. Ubuntu Vagrant Box Version
    This can be changed in Vagrant file from below section.


    https://app.vagrantup.com/generic/boxes/ubuntu2204

  2. CPU & Memory for Kubernetes Master & Worker Nodes (Virtual Box)
    This can be changed from below section in Vagrant file.
    image

  3. Number of Kubernetes Worker Nodes
    This can be changed from below section in Vagrant file.
    image

  4. Kubernetes Version
    This can be changed from bootstrap.sh file

Steps to follow

Please follow the below instructions for creating a kubernetes cluster with master 7 worker nodes, with containerd runtime.

  1. Copy the attached zip file, extract and place it in a folder in system.

  2. Start the Oracle Oracle Virtual Box manager as Administrator.

  3. Start the command prompt as Administrator, and navigate to path where the files have been placed.

  4. Execute the following command: vagrant up


  5. Check the Oracle Virtual Box Manager to see if all the boxes have been created and in running mode.

  6. Now, we can connect to any of the Master or worker Nodes from ftp clients like Mobaxterm/Putty/Winscp using IPs defined in Vagrant file.

  7. We will open Mobaxterm, and connect to kubernetes master node, over 172.15.15.100, as per default setup.
    Username: vagrant Password: vagrant

  8. Execute the below commands to check kubernetes cluster status.
    kubectl cluster-info
    kubectl get nodes

  9. Next, we will create sample deployments of nginx using below commands.
    We can also see which worker nodes this pods are getting created in to.
    kubectl create deploy nginx --image nginx
    kubectl create deploy nginx2 --image nginx
    kubectl get all -o wide

Next steps

  1. User ‘root’ credentials for Virtual boxes:
    UserName: root
    Password: vagrant

  2. For stopping the kubernetes cluster temporarily, please use the below command from command prompt by navigating to folder where vagrant files are stored:
    vagrant halt

  3. For deleting the cluster below command can be used from command prompt by navigating to folder where vagrant files are stored:
    vagrant destroy
    vagrant destroy -f (for force deletion)

Useful links | Relevant resources

  1. Files required for this setup:
    VagrantProvisioning_k8s.zip (3.2 KB)

  2. Some useful containerd commands are
    ctr -h
    sudo ctr namespaces list
    sudo ctr --namespace k8s.io containers list

  1. Useful link for understanding different container runtimes:
    https://www.tutorialworks.com/difference-docker-containerd-runc-crio-oci/
    Docker vs. Containerd: A Quick Comparison (2023)
1 Like