Getting Started with k0s and libvirt
This example shows how to create a single-node k0s cluster in a local VM using Terraform and libvirt. The blueprint-operator may then be installed.
Prerequisites
Along with blueprint
CLI, you will also need the following tools installed:
- k0sctl - required for installing a k0s distribution
- terraform - for creating VMs
- libvirt - required for running the local VM
- terraform-provider-libvirt - required for provisioning libvirt VMs through terraform
You will also need an SSH key for authentication with the created VM.
Create virtual machines
Creating virtual machines can be done using the example Terraform scripts.
After copying the example TF scripts to your local machine, you can create the VMs with the following steps:
- Create a
terraform.tfvars
file with content similar to:
cluster_name = "blueprint-cluster"
cores = 2
mem_size = "2048"
disk_size = 20
user_account = "user"
ssh_public_key = "ssh-rsa AAAEXAMPLE user@example.com"
ssh_key_path = "/home/user/.ssh/id_rsa"
terraform init
terraform plan
terraform apply
terraform output --raw k0s_cluster > cluster.yaml
To get detailed information about the created VMs, you can use virsh:
virsh machine list
Install Blueprint Operator on k0s
Verify or edit the blueprint created in the previous step,
cluster.yaml
Create the cluster:
bctl apply -f cluster.yaml
Note:
bctl apply
adds kube config context to default location and sets it as the current context
- Update the cluster by modifying
cluster.yaml
and then running:
bctl update -f cluster.yaml
- Monitor the status of the cluster’s Kubernetes pods with:
watch -n 1 kubectl get pods --all-namespaces
Accessing the cluster
The example app addon can now be accessed through the http://<vm-node-ip>:6443
URL.
Cleanup
Delete the cluster:
bctl reset -f cluster.yaml
Delete virtual machines by changing to the example TF folder and running:
terraform destroy