Skip to content

Instantly share code, notes, and snippets.

@amshinde
Last active July 19, 2022 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amshinde/afd723eae88b9b53641c4c118021069f to your computer and use it in GitHub Desktop.
Save amshinde/afd723eae88b9b53641c4c118021069f to your computer and use it in GitHub Desktop.
Installing kcli on Ubuntu

Installing kcli on Ubuntu

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.

Install libvirt

sudo apt-get install 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
curl https://raw.githubusercontent.com/karmab/kcli/master/install.sh | sudo bash

Generate config file for kcli

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

Create default storage pool with this:

sudo kcli create pool -p /var/lib/libvirt/images default
sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images

Try downloading an image:

kcli download image ubuntu2004

You can check the list of available images by running the following command:

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 custom image

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

You can view list of downloaded images by running following command:

 kcli list images
+---------------------------------------------------------+
| Images                                                  |
+---------------------------------------------------------+
| /var/lib/libvirt/images/focal-server-cloudimg-amd64.img |
+---------------------------------------------------------+

Create VM

kcli create vm -i ubuntu2004 myvm
kcli list vm
# wait 5-10 seconds for vm to grab an ip
kcli ssh myvm

Create a Kubernetes cluster

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment