Development Kubernetes cluster under 3 minutes

Tomáš Sapák
2 min readJan 31, 2022

Deploying Kubernetes used to be a pain. Full k8s cluster consists of 4–5 services on the control plane and two on worker nodes. There was some automation tools based on Ansible almost from the beginning, but it was not fun and quick experience (I actually can’t remember to run any Ansible playbook without issues the first time around).

Over the last few years, a lot has changed, and many new deployment tools and Kubernetes distributions appeared. Two of them stand out — k0s from Mirantis and k3s from Rancher Labs. Both are distributed as single binary requiring no additional dependencies, taking approximately 500 MB RAM overhead, and both are 100% API compatible with “full” Kubernetes distro.

Requirements

Before building our first cluster, we will need to install Vagrant¹ and VirtualBox². Vagrant is an excellent tool for describing development environments in a declarative way and VirtualBox is used to deploy those environments. Both applications are available for Windows, macOS, and Linux.

Deployment

Download the following file to a new directory:

Vagrantfile consists of two parts. Lines 14–24 describe the virtual machine and lines 4–12 are shell script executed inside created virtual machine once it’s running and accessible over ssh. Code itself is pretty straightforward:

  • 5 —get and execute k3s installation script
  • 6 — get and execute Helm installation script (Helm is the package manager for Kubernetes)
  • 9–11 — install Longhorn — Longhorn is highly available persistent storage for Kubernetes. A Helm package storing persistent data to Longhorn, can be easily deployed to a public cloud provider like AWS or GCP by replacing storage type Longhorn for AWSElasticBlockStore or GCEPersistentDisk.
  • 17 — IP address to access services deployed on your new Kubernetes cluster from hosting OS
  • 21–22 — the size of virtual machine

To run Vagrant, execute vagrant up in the directory with Vagrant file. Everything should be up and running slightly above 2 minutes (unless you are in the middle of the forest on 2G).

You can check that everything is working by logging into the virtual machine with the command vagrant ssh -c "sudo su" and listing all running pods with kubectl get pods --all-namespaces.

This article demonstrated that you can obtain running Kubernetes cluster without any significant effort even without a public cloud provider, removing one of the biggest obstacles if you want to learn Kubernetes.

--

--

Tomáš Sapák

DevOps engineer, automation, and orchestration enthusiast. Love working with AWS and OpenStack.