kcli is a handy tool for creating disposable VMs. You can also creata Kubernetes and OpenShift clusters with it. Refer to https://kcli.readthedocs.io/en/latest/ for more details. This gist describes the steps needed to setup kcli on an Ubuntu machine.
sudo apt-get install libvirt-daemon-system libvirt-daemon-driver-qemu qemu-kvm
sudo adduser $USER libvirt
# Either logout and login back for the new group to come into effect or use the newgrp command to change the effective group.
newgrp - libvirt
newgrp - $USER
Install kcli, Refer to https://kcli.readthedocs.io/en/latest/#installation
curl https://raw.githubusercontent.com/karmab/kcli/master/install.sh | sudo bash
You can generate a default config file (with all parameters commented) pointing to your local host with:
kcli create host kvm -H 127.0.0.1 local
sudo kcli create pool -p /var/lib/libvirt/images default
sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images
kcli download image ubuntu2004
kcli download image -h
usage: kcli download image [-h] [-a {x86_64,aarch64}] [-c CMD] [-o] [-p POOL] [-u URL] [--size SIZE] [-s] IMAGE
Download Cloud Image
positional arguments:
IMAGE Image to download. Choose between arch centos6 centos7 centos8 centos8stream centos9stream cirros coreos debian8 debian9 debian10 fcos fedora28 fedora29 fedora30 fedora31
fedora32 fedora33 fedora34 freebsd114 freebsd122 freebsd130 netbsd82 netbsd91 netbsd92 openbsd67 openbsd68 openbsd69 dragonflybsd563 dragonflybsd583 dragonflybsd600 gentoo
opensuse rhcos41 rhcos42 rhcos43 rhcos44 rhcos45 rhcos46 rhcos47 rhcos48 rhcos49 rhcoslatest rhel7 rhel8 ubuntu1804 ubuntu1810 ubuntu1904 ubuntu1910 ubuntu2004 ubuntu2010
ubuntu2104 rockylinux84
To download a custom image or an image not present in the above list:
kcli download image -u https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img ubuntu2204
kcli list images
+---------------------------------------------------------+
| Images |
+---------------------------------------------------------+
| /var/lib/libvirt/images/focal-server-cloudimg-amd64.img |
+---------------------------------------------------------+
kcli create vm -i ubuntu2004 myvm
kcli list vm
# wait 5-10 seconds for vm to grab an ip
kcli ssh myvm
Use the following command to create a single node K8s cluster on Ubuntu 20.04
kcli create kube generic -P image=ubuntu2004 testk8s
If you want to create a cluster with a single worker:
kcli create kube generic -P image=ubuntu2004 -P workers=1 testk8s
To delete the cluster:
kcli delete kube testk8s