Table of Contents
In this article, I will explain you how to quickly deploy Kubernetes Cluster using vagrant in 7 Simple Steps. As you might be aware that deploying a full fledge Kubernetes Cluster requires a lot of pre work to be done before you actually make it work. This gets even more problematic when you have to bring up and bring down Cluster in momentarily basis for PoC or any other such work. Well, to address these kind of situations vagrant can become quite handy in Cluster provisioning. You can either create your own Vagrantfile and bootstrap script or even utilize some of the currently available GitHub scripts to provision Cluster. Here we will see the provisioning using one such GitHub Script.
What is Vagrant
Vagrant is an open source tool for building and managing virtual environments in a single workflow. It uses providers like Virtualbox, Hyper-V, VMware, Docker Containers to create virtual application environments.
How to Quickly Deploy Kubernetes Cluster Using Vagrant
Also Read: 70+ Important Kubernetes Related Tools You Should Know About
Step 1: Prerequisites
a) You should have a running Linux System(In my case it is Ubuntu 20.04 LTS
).
b) You should have atleast 4 CPU Core
and 8GB
of memory.
c) You should have apt
and git
available in your System.
Step 2: Update Your Server
It is essential to run System update using apt update
or apt-get update
command to let the System know if there are any updates or a new package available in the repo.
NOTE:
root
user to run all the below commands. You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.root@localhost:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:3 https://download.docker.com/linux/ubuntu focal InRelease
Hit:4 http://ppa.launchpad.net/hluk/copyq/ubuntu focal InRelease
Hit:5 https://artifacts.elastic.co/packages/oss-7.x/apt stable InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:8 https://dl.google.com/linux/chrome/deb stable InRelease
Get:9 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Step 3: Install Virtualbox
Since Vagrant uses Virtualbox as a provider to create virtual machines so before using vagrant script you need to install Virtualbox first. On Ubuntu based Systems, you can install it by using apt install virtualbox
command as shown below. For installation on other Linux Systems, you can check the steps on Virtualbox Official website.
root@localhost:~# apt install virtualbox
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
dctrl-tools dkms libdouble-conversion3 libgsoap-2.8.91 liblzf1 libpcre2-16-0 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5opengl5
libqt5printsupport5 libqt5svg5 libqt5widgets5 libqt5x11extras5 libsdl1.2debian libvncserver1 libxcb-xinerama0 libxcb-xinput0 qt5-gtk-platformtheme
qttranslations5-l10n virtualbox-dkms virtualbox-qt
Suggested packages:
debtags menu qt5-image-formats-plugins qtwayland5 vde2 virtualbox-guest-additions-iso
The following NEW packages will be installed:
dctrl-tools dkms libdouble-conversion3 libgsoap-2.8.91 liblzf1 libpcre2-16-0 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5opengl5
libqt5printsupport5 libqt5svg5 libqt5widgets5 libqt5x11extras5 libsdl1.2debian libvncserver1 libxcb-xinerama0 libxcb-xinput0 qt5-gtk-platformtheme
qttranslations5-l10n virtualbox virtualbox-dkms virtualbox-qt
0 upgraded, 24 newly installed, 0 to remove and 43 not upgraded.
Need to get 55.1 MB of archives.
After this operation, 226 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Step 4: Install Vagrant
You can go to How to Install Vagrant on Ubuntu 20.04 LTS [Step by Step] and check the steps to install Vagrant on Ubuntu 20.04 LTS System in great detail. For installation on other Linux systems, you can check the steps on Vagrant Official website.
Step 5: Clone Repository
You can use an existing vagrant script from GitHub to create Kubernetes Cluster. You just have to take the URL and clone it in your local System using git clone https://github.com/justmeandopensource/kubernetes command as shown below. This will create a local directory with the name same as repo with all the contents available inside.
root@localhost:~# git clone https://github.com/justmeandopensource/kubernetes
Cloning into 'kubernetes'...
remote: Enumerating objects: 789, done.
remote: Counting objects: 100% (125/125), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 789 (delta 62), reused 101 (delta 49), pack-reused 664
Receiving objects: 100% (789/789), 156.30 KiB | 1.74 MiB/s, done.
Resolving deltas: 100% (422/422), done.
Step 6: Deploy Kubernetes Cluster
After cloning repo, you need to go inside vagrant-provisioning folder using cd kubernetes/vagrant-provisioning/
command and then run vagrant up
to start provisioning the cluster. This command will bring up the cluster based on Vagrantfile configuration.
root@localhost:~# cd kubernetes/vagrant-provisioning/ root@localhost:~/kubernetes/vagrant-provisioning# vagrant up Bringing machine 'kmaster' up with 'virtualbox' provider... Bringing machine 'kworker1' up with 'virtualbox' provider... Bringing machine 'kworker2' up with 'virtualbox' provider... ==> kmaster: Box 'generic/ubuntu2004' could not be found. Attempting to find and install... kmaster: Box Provider: virtualbox kmaster: Box Version: 3.3.0 ==> kmaster: Loading metadata for box 'generic/ubuntu2004' kmaster: URL: https://vagrantcloud.com/generic/ubuntu2004 ==> kmaster: Adding box 'generic/ubuntu2004' (v3.3.0) for provider: virtualbox kmaster: Downloading: https://vagrantcloud.com/generic/boxes/ubuntu2004/versions/3.3.0/providers/virtualbox.box
Step 7: Verify Cluster
Once provisioning is completed, you can verify the cluster status using vagrant status
command. This should show you one master and two worker nodes running as shown below. To login to any of the nodes, you can use vagrant ssh <node> command.
root@localhost:~/kubernetes/vagrant-provisioning# vagrant status Current machine states: kmaster running (virtualbox) kworker1 running (virtualbox) kworker2 running (virtualbox) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.