Deploy Kubernetes Cluster on Workstation Using VirtualBox

Deploy Kubernetes Cluster on Workstation Using VirtualBox

Overview

This page describes how to create a minimal on-premises Kubernetes cluster on a workstation using VirtualBox.

Objectives

  1. Create virtual machines with Kublr
  2. Create a Kubernetes cluster

Prerequisites

Create virtual machines

You will need to to create 3 virtual machines:

  • a VM for Kublr with Ubuntu Server 18.04,1 GiB RAM and 10 GB disk space
  • a VM for the master node with Ubuntu Server 18.04, 5 GiB RAM and 10 GB disk space
  • a VM for the worker node with Ubuntu Server 18.04, 4 GiB RAM and 10 GB disk space

Additional requirements:

  • The master and worker nodes should be accessible from the Kublr VM via SSH with sudo with no password
  • The Kublr VM should expose port 9080 to the host to make the Kublr UI accessible to the administrator

Create a directory and go there:

mkdir my-cluster
cd my-cluster
touch Vagrantfile

Edit Vagrantfile via your favorite IDE or editor. Here is example content:

KUBLR_IP = "172.28.128.10"
MASTER_IP = "172.28.128.11"
WORKER_IP = "172.28.128.12"
 
MASTER_MEMORY_MB = "5120" #5G
WORKER_MEMORY_MB = "4096" #4G
 
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.define "kublr" do |kublr|
    kublr.vm.network "private_network", ip: KUBLR_IP
    kublr.vm.provision "docker" do |d|
      d.run "kublr", # --name kublr
            image: "kublr/kublr:1.18.0",
            daemonize: true, #-d
            restart: "unless-stopped", # --restart=unless-stopped
            args: "-p 9080:9080"
    end
    kublr.vm.provision "shell", inline: "docker exec -i kublr /bin/bash -c 'echo \"KUBLR_HOST=#{KUBLR_IP}:9080\" > /ip.external'; docker restart kublr"
  end
  config.vm.define "master" do |master|
    master.vm.network "private_network", ip: MASTER_IP
    master.vm.provider "virtualbox" do |vb|
      vb.memory = MASTER_MEMORY_MB
    end
  end
  config.vm.define "worker" do |worker|
    worker.vm.network "private_network", ip: WORKER_IP
    worker.vm.provider "virtualbox" do |vb|
      vb.memory = WORKER_MEMORY_MB
    end
  end
end

Pay attention to VM IPs:

KUBLR_IP = "172.28.128.10"
MASTER_IP = "172.28.128.11"
WORKER_IP = "172.28.128.12"

Make sure that they belong to a private address space, but not to an existing local network. Vagrant will create a corresponding private network.

Bring up the infrastructure:

vagrant up

It takes a few minutes to create the VMs and install Kublr

Kublr UI will be available at http://172.28.128.10:9080

Add SSH keys

Go to the Credentials tab and add the SSH private key for the master VM The key itself is stored in .vagrant/machines/master/virtualbox/private_key

Add Master Key

Add the key for the worker VM It is stored in .vagrant/machines/worker/virtualbox/private_key

Create Cluster

  1. Click on Cluster Menu in Left Navigation Menu Bar

  2. Click on Add Cluster Add New Cluster

  3. Enter Cluster Name.

  4. Select Provider: Bring Your own Infrastructure Provider

  5. Click the INSTANCES step.

  6. Use the Master Configuration section.

  7. Enter master parameters:

    • User Name: vagrant
    • SSH Key Name: the private SSH key for the master VM added before
    • IP/DNS of Master 1: IP of the master VM specified in Vagrantfile Master
  8. Scroll to the Instance Group section (default name group1).

  9. Specify the parameters of the work node(s) in your group as described below:

    • User Name: vagrant
    • SSH Key Name: the private SSH key for the worker VM added before
    • Add IP/DNS Addresses: IP of the worker VM specified in Vagrantfile Worker
  10. Click on CUSTOMIZE CLUSTER SPECIFICATION Customize Button

  11. Disable logging and monitoring:

  • Set spec.features.logging.logCollection.enabled to false

  • Set spec.features.monitoring.enabled to false

  • Click on CREATE CLUSTER

    Features

    In a few minutes the cluster will be created.

    Cluster