In order to provide a set of virtual hosts to create our Kubernetes cluster with Ansible we can provision some Debian 11 VMs using Vagrant.
Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can automatically install and configure software on the virtual machine.
Name | Link | Version |
---|---|---|
Hyper-V | Microsoft Docs | Bundled with Windows |
OpenSSH Client | https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse | Bundled with Windows |
Vagrant | Download | Latest |
Vagrant Host Manager Plugin | Github Repo | N/A |
In order to provision the VMs we need some preparation.
-
Install Vagrant and enable Hyper-V (refer to their respective documentations)
-
Ensure you have a valid LAN/WLAN connection and that there is no External Virtual Switch connected to your network adapter.
-
Using powershell, install the Vagrant Host Manager Plugin:
vagrant plugin install vagrant-hostmanager
-
Run the
create-hyperV-virtual-switch.ps1
script in this folder to create the External Virtual Switch, you will be prompted to choose which network adapter to bind it. -
Edit the
WORKER_NODES
constant at the start of theVagrantfile
to your preference. For the master node, 4GB of ram and 2CPUs will be allocated. For each worker node, 2GB and 1CPU. This values can be changed using the corresponding constants. -
In order for Ansible to connect to our VMs it's required to have a SSH key beforehand, with the object of inserting it into the VMs. The public key must be available on
%userprofile%/.ssh/id_rsa.pub
.This can be done by enabling OpenSSH Client and generating a key:
ssh-keygen
After preparing the environment is just a matter of running the following command in the vagrant directory and waiting a couple of minutes:
vagrant up
To destroy all the VMs, just run:
vagrant destroy --force
By default all VMs will register on the specified network adapter's network using DHCP, their IPs are printed while the VMs create.
VMs will also broadcast and reach themselves through mDNS/DNS-SD. The master node is available at master-node
and the worker nodes at worker-node01 worker-node02 ... worker-node0N
. This will be particularly useful when we provision them using ansible, we will not need to type any IP that may be prone to changing.