Sunday, February 16, 2020

Vagrant Plugins

1: The disksize plugin
Ever created a VM with a specific size for the disk and after using it for a while, you find out you would have liked to have a larger size disk? You can resize the VDI in for example.
you can ask Vagrant to give you the disk size you want to have?
Enter the vagrant-disksize plugin.
Install it with
vagrant plugin install vagrant-disksize
And you can use it in your Vagrant file like:
config.disksize.size = '75GB'
It will figure out what to do and do it!

2: The vbguest plugin
Getting tired of installing guest additions after each and every new installation and keeping them updated after a new version of VirtualBox is released? Mounting an ISO, installing the required dependencies, running the installer… You don’t have to worry about those things anymore! The vagrant-vbguest plugin takes care of this for you.
Install it with:
vagrant plugin install vagrant-vbguest
And add to your Vagrantfile a line like:
config.vbguest.auto_update = true
This installs the correct version of the guest additions and also installs dependencies if required to for example build the module.

3: Install missing plugins
If I want to share a Vagrantfile, When my Vagrantfile depends on plugins such as above, it won’t work if they are missing. Luckily installing missing plugins is easy to automate within your Vagrantfile like below:
unless Vagrant.has_plugin?("vagrant-disksize")
puts 'Installing vagrant-disksize Plugin...'
system('vagrant plugin install vagrant-disksize')
end
unless Vagrant.has_plugin?("vagrant-vbguest")
puts 'Installing vagrant-vbguest Plugin...'
system('vagrant plugin install vagrant-vbguest')
end
unless Vagrant.has_plugin?("vagrant-reload")
puts 'Installing vagrant-reload Plugin...'
system('vagrant plugin install vagrant-reload')
end


This way you don’t have to first install the plugins before you can use the Vagrantfile. Inspiration from the Oracle provided Vagrantfiles here.

4: Execute a command once after a reboot
Suppose you want to have a specific command executed only once after a reboot. This can happen because a specific command could require certain files not to be in use or for example the vagrant user not to be logged in. You can do this with a pre-script (prepare), the reload plugin and a post script (cleanup). The below example should work for most Linux distributions:
Inside your Vagrantfile:
config.vm.provision :shell, path: "prescript.sh"
config.vm.provision :reload
config.vm.provision :shell, path: "postscript.sh"
Pre-script: prescript.sh
chmod +x /etc/rc.d/rc.local
echo ‘COMMAND_YOU_WANT_TO_HAVE_EXECUTED’ >> /etc/rc.d/rc.local
Post-script: postscript.sh
chmod -x /etc/rc.d/rc.local
sed -i ‘$ d’ /etc/rc.d/rc.local

The pre-script adds a line to rc.local and makes it executable. The postscript removes the line again.

5: Installing docker and docker-compose
For installing docker and docker-compose (and running containers) there are 3 main options.
Using Vagrant plugins
This is the easiest option and does not require specific provisioning file entries. The Docker provisioner is provided as part of Vagrant out of the box. Docker-compose requires the installation of a plugin.
vagrant plugin install vagrant-docker-compose
Inside your Vagrantfile
config.vm.provision :docker
config.vm.provision :docker_compose

Using these plugins, you might have to look into how you can force it to use a specific version should you require it.
Using a provisioning script and OS repositories

Thursday, February 13, 2020

Server-side and Client-side Load Balancing for HA

Eventually you'll reach a point where you need to run multiple instances of an application or a service for high availability or to manage increased load. That's what load balancer are for.
There's generally two different types:
  1. Server-side load balancers
  2. Client-side load balancers
Server-side Load Balancing :
What many people would call a "load balancer" is actually a server-side load balancer. It can be implemented in hardware or software. The traffic is sent to a dedicated service that decides where to send the traffic, using an algorithm like round-robin, to one of the many instances. 


Server-side load balancing
Client-side Load Balancing :
Instead of relying on another service to distribute the load, the client itself, is responsible for deciding where to send the traffic also using an algorithm like round-robin. It can either discover the instances, via service discovery, or can be configured with a predefined list. Netflix Ribbon is an example of a client-side load balancer.


Client-side load balancing