Kcli — the only tool you will need to create Kubernetes and OpenShift cluster for test and development

Pradipta Banerjee
3 min readMay 21, 2022

--

I often create disposable Kubernetes and OpenShift clusters in my day-to-day development work. Mostly it’s on my bare metal server. However, sometimes I use public cloud providers as well. Creating disposable clusters improved my productivity compared to my earlier approach of cleaning up and reusing existing clusters.

I have used scripts, ansible playbooks, and terraform templates, among other things. Eventually, I got introduced to the kcli tool and there is no looking back.

You can use kcli to create VMs or spin up Kubernetes clusters. Most importantly, it works with different virtualization and cloud providers, e.g. libvirt, aws, vsphere, etc.

You can also use it to create OpenShift clusters with different combinations — regular cluster, single node (SNO), disconnected, etc.

Let’s see some sample usage using the libvirt provider.

Setup kcli

The easiest is to simply run the following command to install kcli

curl https://raw.githubusercontent.com/karmab/kcli/master/install.sh | sudo bash

Check out the documentation for custom install methods — https://kcli.readthedocs.io/en/latest/#installation

Here is what I use on my local development system running libvirt/KVM

mkdir -p $HOME/.kcli
ssh-keygen -t rsa -N '' -f $HOME/.ssh/id_rsa

alias kcli='docker run --net host -it --rm --security-opt label=disable -v $HOME/.ssh:/root/.ssh -v $HOME/.kcli:/root/.kcli -v /var/lib/libvirt/images:/var/lib/libvirt/images -v /var/run/libvirt:/var/run/libvirt -v $PWD:/workdir quay.io/karmab/kcli'

kcli create network -c 192.168.121.0/24 kubernetes

kcli create pool -p /var/lib/libvirt/images default

sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images

Note: You’ll get the message “pool default already there, leaving” if the pool already exists.

Once kcli is installed, you’ll need to configure the virtualization provider.

For local libvirt no specific configuration is required. For other providers, a config is required in $HOME/.kcli/config.yml.

For example, my AWS config

aws:
type: aws
access_key_id: AKAAAAAAAAAAAAA
access_key_secret: xxxxxxxxxxyyyyyyyy
region: ap-south-1
keypair: bpradipt-key

Refer to the kcli documentation for provider configuration details.

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

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

kcli list images

If you require a specific Kubernetes version:

kcli create kube generic -P image=ubuntu2004 -P version=1.21 testk8s21

If you want to create a cluster with a single worker:

kcli create kube generic -P image=ubuntu2004 -P workers=1 testk8s

You can also create a parameter file and use the same for cluster creation.

To list out all the options, you can run the following command.

kcli info cluster generic 

Create a ‘parameters’ file with the relevant options as per your requirements and then create the cluster.

For example, this is a sample ‘parameters’ file to create a two-node Kubernetes cluster with Kata containers runtime deployed.

cat > k8s_param.yaml << EOF
api_ip: 192.168.121.100
cluster: testk8s
domain: kata.com
pool: default
image: ubuntu2004
masters: 1
workers: 1
network: kubernetes
apps: ["katacontainer"]
nip: true
EOF
kcli create kube generic --paramfile k8s_param.yaml

Deleting the Kubernetes cluster

kcli delete kube testk8s

Create an OpenShift cluster

Download OpenShift pull secret from the following link — https://console.redhat.com/openshift/install/pull-secret

View the available options by running the following command.

kcli info cluster openshift

Create a parameters file. Here is an example file that I use to deploy OpenShift 4.10 — https://gist.github.com/bpradipt/56a74359358e2235737ea19568b833d4

You can tweak it as per your requirements.

Create the cluster by running the following command.

kcli create kube openshift --paramfile <parameters file>

You can even install different OpenShift operators.

List available operators by running the following command.

kcli list app openshift

Example command to install the OpenShift sandboxed containers operator

kcli create app openshift sandboxed-containers-operator

Kcli has been a blessing in disguise for my Kata containers development work on OpenShift and Kubernetes. I hope you find this tool useful.

This article was first published here

--

--

Pradipta Banerjee
Pradipta Banerjee

Written by Pradipta Banerjee

Writes about technology | Startup advisor & mentor. www.linkedin.com/in/bpradipt

No responses yet