How To Setup Vagrant and Virtual Box for Ubuntu 20.04!!

A quick and easy guide to setting up a production environment on your local machine.

Akash Rajvanshi
DevOps Dudes
5 min readSep 22, 2020

--

Vagrant + Virtual Box = Absolute Fun

Overview

What is Vagrant??

Vagrant is an open-source software product for building and maintaining portable virtual software development environments, e.g., for Virtual Box, KVM, Hyper-V, Docker containers, VMware, and AWS.

What is Virtual Box??

Oracle VM Virtual Box is a free and open-source hosted hypervisor for x86 virtualization, developed by Oracle Corporation. Created by Innotek, it was acquired by Sun Microsystems in 2008, which was, in turn, acquired by Oracle in 2010. Virtual Box can be installed on Windows, Mac-OS, Linux, Solaris, and Open Solaris.

Virtual Box + Vagrant = 🔥

Vagrant and Virtual Box can stimulate the production environment of your app or website. For example, suppose you’re using Digital Ocean or AWS to run a Virtual Private Server (VPS) in the cloud running Ubuntu, PHP, and MySQL. In that case, you can install your local version to have all the same versions of that software while keeping your own computer’s software untouched. These both can reduce and eliminate bugs and errors that result from trying to develop code for a production server on an environment that does not match. So with these, you can create VMs in a virtual box in just one command with so much customization.

Install Virtual Box

Download Virtual Box 5.2.x ( Latest ) and its Extension Pack from Virtual Box 5.2.x Builds. I am using virtual box 5.2.x because the vagrant gives a problem with 6.x sometimes. That’s why I m using 5.2.x (It’s working like a charm ).

Virtual Box Installation for Ubuntu

Install Vagrant

Vagrant Installation for Ubuntu

Let’s Deploy Some Fun 🔥

Here, we start 2 Ubuntu 18.04 VM’s with vagrant, and we set up the Kubernetes cluster on nodes ( 1 work as master node & other work as worker node ) in just less than a minute. So, let’s start the journey 🎇:

Directory Structure

First of all, you need to create VM’s with vagrant. To create VM’s with vagrant, you need to create a file name Vagrantfile. This given Vagrantfile will set up two Ubuntu 18.04 VM’s in VirtualBox.

Deploy the VM’s

We set up the Kubernetes cluster on both nodes ( 1 Master, 1 Worker Node). To do this whole process, we are using ansible.

To setup ansible ( You need to install ansible on your working machine )
Now, you need to create some ansible config files so that Ansible can connect to the nodes.

  • hosts
hosts
  • ansible.cfg
ansible.cfg

To check connection to the nodes with ansible:

To Install Docker

You can install docker on both the nodes in just a 20s.

docker.yaml
files/daemon.json

To Install Portainer

You can install portainer on both the nodes in just 6s. ( To access the portainer http://NodeIP:9000 )

portainer.yaml
vars/default.yml

To Install Kubernetes

You can setup Kubernetes using microk8s in just 11s.

Last Step:

Congratulations 🎊, You’ve just set up two ubuntu nodes with docker, portainer & Kubernetes cluster in less than a minute!!

Conclusion

Now, you’ve operational experience using vagrant and the virtual box together and set up both of them easily in any operating system. Also, you can effortlessly create VMs using vagrant to set up things like Docker, Kubernetes, and other more.

Find something useful? Hold down the 👏 to support and help others find this article. Thanks for reading!!

Follow me on Instagram @hypnosisss___ & Twitter @akash_Rajvanshi

--

--