Gluster blog stories provide high-level spotlights on our users all over the world
|Automated cluster creation in VMs by scriptifying your KVM setups.|
Automatically provisioning VM clusters comes up alot:
A few weeks ago we went through setting up single node, rebuildable gluster VM directly from source using KVM.
But — the guilt of having to click the Virtual Machine Manager UI just to browse for a path to an ISO was unbearable… So… I finally forced myself how to figure out how to automatically deploy VMs using virt-install.
Enter KVM + virt-install + Kickstart
After trying it out – I can honestly say that KVM’s virt-install with kickstart on Fedora/RHEL is an excellent alternative to Vagrant (albeit KVM specific). See the vagrant gripes regarding overabstractions here https://news.ycombinator.com/item?id=4406467, many of which are solved by kickstart’s much simpler paradigm.
However, the use of kickstart with KVM requires a little extra research because of its lower level and more powerful feature subsets. In any case, I’m no virtualization expert and I got it working. Like most things, once you get a solid template to work from, its easy to incrementally learn and customize.
So here’s how to “scriptify” Fedora16 VM creation ~ using the virt-install utility (which is like a programmatic version of the Virtual Machine Manager).
virt-install –name VM-MyNewVM-1 –hvm –ram 1024 –disk path=/VirtualMachines/VM-MyNewVM-1.img,size=10,size=10 –network network:default –vnc –os-type=linux –os-variant=fedora16 –location http://redhat.download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/x86_64/os/ -x “ks=http://pastebin.com/raw.php?i=UUX1qcpa“
^^ Yup – thats it. That ONE LINE of shell script created a 1GB VM for you with (if you include the “pastebin” script whose contents are below) disk partitions and a static ip.
(note, I’ve since updated this with some snippets from this excellent minimal fedora kickstarter template https://gist.github.com/bburky/2913219 to make the install leaner)
# CONTENTS OF THE PASTEBIN SCRIPT ABOVE
# Kickstart file automatically generated by anaconda.
network --onboot yes --device eth0 --bootproto dhcp --noipv6
timezone --utc America/New_York
rootpw --iscrypted $6$9bRPXTZZMy0FNl2A$lgY.MS3pZ.0PVg4o3AQeJOydPwGVphdKT07tHlJUmdoRTz4UQQ/L54ny0QHkdubMquqkr4jw37DxmM0FL5kRn1
authconfig --enableshadow --passalgo=sha512
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
# Uncommented by j
#Static IP address with gateway to the outside world - 192.168.122.1 is the default KVM gateway.
network --bootproto=static --ip=192.168.122.99 --netmask=255.255.255.0 --gateway=192.168.122.1 --nameserver=192.168.122.1
bootloader --location=mbr --timeout=5 --append="rhgb quiet"
Dayumnnn… How does this work?
Here’s whats embedded in the action packed virt-install command above:
So, in summary – to start with, the only parameters you need to modify above are – You can change:
Kickstarting your kickstart scripts…
So -> how do you build a create a kickstart script from scratch ? You don’t have to 🙂 …
Fedora/RHEL create a kickstart script for you when you do a manual install, just setup your first VM manually and use its autogenerated kickstart (which is created based on how you setup the OS, and written to /root/anaconda.cfg).
Once I ran this file, I found it wasn’t completely automated, i.e. the disk partitions were being requested by Fedora interactively. To squelch this, I added the zerombr and the clearpart commands into the kickstart, In the end, my bare bones kickstart template looked a little like this…
KVM supports post scriplets and “ks_append” tags. These essentially will run shell commands for you after the box is setup. For example, you can append this to the end of your file.
Testing that it worked:
Make sure you got your static IPS and disks right —>
1) ifconfig | grep 192 #Confirm that the static ips were assigned properly from the kickstart script.
2) df -h /root #Confirm that /root has several gigs of space in it. For fancier provisioning, replace the autopart (which I found was necessary, along with clearpart –all, to avoid the fedora interactive “Storage Device Warning” dialog.
Parting Words …
Virt-install can be used with a kickstart script to automate VM creation with static ips, disk partitions, memory, and a whole host of other goodies, right off the bat – and that means that virt-install can set up an entire cluster for you.
Admittedly, the syntax is not as elegant and its not platform neutral as the similar vagrant tool… But who cares? You can customize it to any degree – both on the hardware side and the user space packages. For example, there are kickstarter templates for complex deployments, minimal servers and combining your kickstart script with shell commands to do installations of packages at the end of OS setup.
2020 has not been a year we would have been able to predict. With a worldwide pandemic and lives thrown out of gear, as we head into 2021, we are thankful that our community and project continued to receive new developers, users and make small gains. For that and a...
It has been a while since we provided an update to the Gluster community. Across the world various nations, states and localities have put together sets of guidelines around shelter-in-place and quarantine. We request our community members to stay safe, to care for their loved ones, to continue to be...
The initial rounds of conversation around the planning of content for release 8 has helped the project identify one key thing – the need to stagger out features and enhancements over multiple releases. Thus, while release 8 is unlikely to be feature heavy as previous releases, it will be the...