Quote
Hi @all, How are you going, great huh π. Graceful and especially to announcing about
kubewekend
- new series of mine, which one to give me and you opportunities to learn about new technologies, the way to bring you nearkubernetes
and more a lot of things pick a up arounddevops
,networking
,devsecops
,pipelines
and moreover. And today, the first session, let dive deeper into way for setup the VM on your host, I mean how can we automate provisioning to create your machine withvagrant
, that is factor to doing a lot of stuff when you want to operate something in your host, especiallykubernetes
. Not wait to long, letβs digest π
List of topics in series
What is vagrant ? Why I use it ?
Like usual, before start a lab, we will figure out what things we do interact, and how we can handle and understand about useful that tools can bring up for us. And vagrant
is special target, much powerful and easily to hang out when you want to work in vm
with virtualbox
, hyper-v
and vmware
If this is first time you hear about vagrant
, then vagrant
is
Introduce Vagrant
Info
Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the βit works on my machineβ excuse a relic of the past.
Vagrant
is one in tools of Hashicorp
, which community provide us about powerful solution in Managing Infrastructure by code, such as
- Terraform
- Nomad
- Packer
- Consul
- And yeah, Vagrant
Back to Vagrant
, this tool can help you handle the work when you want to build virtual machine environments in a single workflow, you will except mistake when you setup hand by hand for virtual machine and cut off effort to setup your projects, help maximize the productivity and flexibility of you and your team.
Fact
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.
Vagrant is designed to use for multiple purpose and personal reason
- For Developer,
Vagrant
will isolate dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of the tools you are used to working with (editors, browsers, debuggers, etc.) - For Operators,
Vagrant
gives you a disposable environment and consistent workflow for developing and testing infrastructure management scripts. - For Designers,
Vargant
will automatically set everything up that is required for that web app in order for you to focus on doing what you do best: design.
Note
Vagrant is designed for everyone as the easiest and fastest way to create a virtualized environment! π€
Read more about Vagrant
versus with others software, at : Vagrant vs. Other Software
Vagrant Fundamentals
The special of Vagrant
comes up with multiple features, and active community to help you doing great things, let me tell you
- Boxes - The package format for Vagrant environments, that will factor like light weight image which package and provide to reuse that for bring up virtual environment
- Vagrantfile - Describe your virtual machineβs configuration and how to provision it
- Provisioning - Workflow help you automatically install software, alter configuration, and do lot of things with machine
- Vagrant Cloud - Huge providers to give you boxes which can interact with
vagrant
- And a lot of things, CLI Synced Folders Networking
Explore more about Vagrant
and features at Documentations
Installation
Vagrant
is CLI, as binary and work for multiple platforms from Mac, Win and Linux. You can install from install page and follow instruction to installing
So simple if you work with Linux
, especially Ubuntu or Debian, you can follow my guide to install Vagrant
Done after move to directories, you can check vagrant
on your shell
Vagrant workflow
Base on my experience, when work with vagrant
, you will make sure some stuff already exist and make sure your step can occur smooth and no problems
- Prepare environment variables if need
- Validate
Vagrantfile
configuration withvalidate
command - Check providers actually install and work on your machine
- Use
up
command when you validate all above, and others will handle viaVagrant
- After provisioning progress, Use
ssh
command to connect machine
Conclusion
Quote
Hope you find well information about
vagrant
, figure out the technology which you work with. Donβt worry to ton of information because on the next part, when you do the lab, I think you will actually lovevagrant
, for sure 100% π
Do magical with Vagrant
Introduce Lab
Todo
On session 1, we will use
vagrant
to provisioning the machine inVirtualBox
, and preparedocker
environment inside to next session, you will deploykubernetes
cluster withdocker
inside that machine
Source Lab: Use Vargrant to configuration the VM with provider
That is my source code about kubewekend
series, you can follow and take new update from progress of series, what lab does we have in table of contents
Before you can do the lab, make sure you do
- InstallΒ virtualbox
- InstallΒ vagrant
With Virtualbox
, if you meet the problem to install or unable to start virtualbox
service, you can reach out to virtualbox troubleshoot which can help use to resolve problem (NOTICE: Ubuntu 24.04 can be meet)
If you check all work, VBoxManage
and Vagrant
like this
You is already to do provisioning VM with Vagrantfile
, but before review file, you can perform box add
command to cut off the time to waiting download box from Vagrant Cloud. To be stable and not increase the trouble, we will use Ubuntu 20.04 - focal64
It will start download box
and you can check result on the last of progress, with box list
command
Vagrantfile
Now, we overview Vagrantfile
, I try to setup multiple case for you meet when work with vagrant
, such as
- Iteration loop (Use for in
ruby
) - Set up
priority
for your step in provisioning machine - Overwrite
ssh
default port to customize of your - Disable password and use
private_key
to authentication - Use
env
inVagrantfile
with.env
file - Write
provision
withshell
block to installingdocker
- Configuration
trigger
when you doup
andprovision
with machine - Use regex to handle
provision
multiple machine
So Vagrant
is use ruby
major language to write this file, so syntax will like a ruby
a lot. Inside this Vagrantfile
, I will do three task when you use up
command
- Tell
Virtualbox
, build and define the machine base on name we will pass into, e.g:k8s-master-machine
,k8s-worker-machine-1
. Especially, I define dynamic worker machine to help you learn about high availability (HA) on this series, so you can useregex
which I refer on description aboutdescription
to parallel build multiple machines, e.g use"/k8s-worker-machine-[1-2]/"
to up machine 1 and 2 - When you trigger
up
you can performssh
and do provision shell script to install docker engine inside that machine. You can update script what ever you want and re-trigger withprovision
command - Lastly, when you use
up
andprovision
command, your machine will restart base on trigger event which I setup on the last, to apply and use new profile whichreboot
options
You can learn more about Vagrantfile
at Vagrantfile that will include multiple topics and configuration about vm
ssh
winrm
winssh
vagrant
After you make sure learn and feel pleasure with your Vagrantfile
. You can save that do next step
Make a magic
When you choose the Vagrantfile
of mine, you can do step by step to get the goal
-
First, locate to the root of project
-
Secondly, you need to make sure set environment variables for your shell before execute Vagrant, you can do manually or use
.env
-
Third, use
up
command with provider=virtualbox
Result when you provisioning successfully
Vagrant
note
Note
In this part, I will brief the popular command, that use for control and handle task with
vagrant
Destroy
When you want to destroy, use destroy
command with option to destroy vm
Provision
When you want to execute a shell
script, you can use provision
command
Halt
When you want to turn off the machine provisioning, use halt
command
Reload
When you want to reload the machine provisioning when update Vargrantfile, use reload
command. (NOTE: Use can use that to turn up your machine, but it will regenerate private key, make sure you understand that)
Box
When you want to add a new box to the machine, or cut off time for downloads machine. Use can use box
command
SSH
When you want to connect to the machine, you have two ways to connect
- Via
vargrant
,ssh
command
That situation will use private_key
base on your ssh-config when you define and generate machine, you will not need concert about your key is outdate or whatever, just simple put the responsibility for vagrant
to take care connection
And you access ssh
succeed with vagrant ssh
command
- Via actions with manually configured
ssh-key
Status
You can use status
command to check your state of machine
Conclusion
Success
Yeah that all for today, just few situation around
vagrant
, hope you can learn a lot about them and define your ownVagrantfile
to handle your requirements. As least, I can deliver you some situations you can refer for future update. And lastly of this lab, you have machine withdocker
inside, and be ready for bring upKubernetes
cluster on next session
Quote
Lastly, This is end on the session 1, please wait and join with me in the next issues, you can find suitable topic at Setup Self Kubernetes Cluster in locally β. On the session 2, I will guide you about
ansible
and how we can useansible
to provide for you ownkubernetes
cluster withkind
. And now, I hope you have a good weekend, happy with your family, stay safe and I will see you soon, bye bye π