Deploy Minikube Using Vagrant and Ansible on VirtualBox – Infrastructure as Code

Latest posts by Gineesh Madapparambath (see all)

Okay, you started learning kubernetes; maybe you are following some courses or documentations. Some of the courses are arranged with FREE labs where you can do hands-on labs and test your knowledge. And you can also use the FREE labs around, like kubernetes labs in That’s more than enough, but what if you want to test more on kubernetes clusters other than lab arrangements ?

Find FREE OpenShift Hands on Labs here.

Sometimes, you have situations like you need to test the latest kubernetes version or kubectl version and those FREE labs are not yet ready with those versions. So what, you can easily set up your own kubernetes cluster on your laptop or workstation. But, setting up a full kubernetes cluster is not required in most cases as we have a minimal version of kubernetes called minikube.

So, what is minikube ?

Minikube is a tool to run a kubernetes cluster locally, that means on your laptop or inside a virtual machine. Minikube will run a single node kubernetes cluster on your machine with almost all features you want to try on an actual kubernetes cluster; like DNS, NodePorts,ConfigMaps and Secrets, then kubernetes Dashboard, Container Runtime like Docker, CRI-O, and containerd, and also enabling CNI or Container Network Interface, ingress, yes almost all items you need your hands get dirty.

Is it easy to install minikube ?

Not really and depends on your experience with virtual machines or docker configurations. If you check the minikube installation document, you will find very few steps but it’s not actually.

You can spin up a minikube cluster inside a virtual machine like virtualbox, hyperkit, hyperv, vmware or kvm. Or you can install minikube directly on a physical machine like your laptop or workstation, using --driver=none. But that needs docker to be installed on that machine as kubernetes components will run as docker containers.

A Simple Solution

Let’s say, we need to spin up a minikube cluster whenever we need, quickly and without any hurdles, then we can mix up some of the solutions and implement this minikube as Infrastructure as Code or IaC. We will use vagrant to provision the virtual machine, then we will use Ansible as a provisioner and install all those required packages. For this demo, we will use VirtualBox as a hypervisor, but you may try with any other hypervisor or public cloud solutions.

Why Vagrant

Vagrant is one of the easiest tools to provision infrastructure or virtual machines in a single workflow and this is available for Windows, MacOS, Linux, Debian, Centos etc.

Why Ansible

Ansible is super simple and powerful in terms of its usage. Once you start using Ansible, you will realize that this is simpler than shell script. Please note, Ansible is not natively available for Windows yet and you might need some extra setup like cygwin to achieve this in a windows environment. Later I will share the shell script version of the same but for this demo we will use Vagrant + Ansible.

Why Infrastructure as Code

We will not go in details as our focus is on minikube cluster setup. But just to add, you have several reasons to implement IaC.

  • Your infrastructure will be defined and changes will be transparent. Every time you create the infrastructure, it will be consistent. For example, you can share your infrastructure code to your colleague or different team and they can implement their own infrastructure in a consistent way; like I am sharing my Vagrantfile with you for this minikube demo.
  • Less risk because everything about your infrastructure is already visible on your code and any engineer can easily handle it; means less dependence on an engineer.
  • It will increase efficiency as you can focus on actual things like coding or designing rather than setting up your infrastructure every time.

In this video, I will explain how to create a minikube cluster very quickly with the help of vagrant and Ansible, that means you will not be required to run a lot of configurations to start the cluster.

Questions ? Please ask in comment box and I will try my best to

Gineesh Madapparambath

(aka Gini Gangadharan)

You may also like...

%d bloggers like this: