🎊Happy New Year 2023! My learning project during the winter vacation.
This is fully containerized evaluation environment to build Kubernetes multi node cluster with k0s. It consists of two containers, one for work and one for the hypervisor. the dev container has the essential tools installed (similar but unrelated to Development Containers). On the other hand, the libvirt container has Libvirt installed and is running on SystemD. So you don't have to manually prepare a virtualization infrastructure or virtual machines. Instead, Terraform and Terraform provider for libvirt make all the steps automated and reproducible. The nodes and cluster configuration is defined as a single file in CUE language, allowing for simple writing and schema validation.
There are many things to be improved, but since the vacation ends today, I'm releasing for now.
- Linux (KVM enabled)
- GNU Make
- Docker Compose
$ make dev # create and enter `dev` container
...
dev:/mnt$ make up # create the virtual machines and the cluster
...
NAME STATUS ROLES AGE VERSION
node-2 Ready <none> 57s v1.25.4+k0s
node-3 Ready <none> 57s v1.25.4+k0sdev:/mnt$ virsh list # manage the virtual machines
Id Name State
------------------------
1 node-1 running
2 node-2 running
3 node-3 runningdev:/mnt$ ssh node-1 # enter the virtual machine
...
node@node-1:~$dev:/mnt$ kubectl get node # manage the cluster
NAME STATUS ROLES AGE VERSION
node-2 Ready <none> 57s v1.25.4+k0s
node-3 Ready <none> 57s v1.25.4+k0sdev:/mnt$ make down # stop the virtual machines and the cluster
dev:/mnt$ make clean # delete the virtual machines and the cluster
dev:/mnt$ exit # exit `dev` container
$ make dev/down # stop `dev` container
$ make dev/clean # delete all files and volumes$ vi config/config.cue # edit the configuration file
$ cat config/config.cue # print the configuration file
package config
cluster: name: "k0s-hands-on"
nodes: [
{name: "node-1", role: "controller"},
{name: "node-2", role: "worker", qemu: {disk: 8Gi}},
{name: "node-3", role: "worker", qemu: {disk: 8Gi}},
]
dev:/mnt$ print-config-as-yaml # validate and print full configuration (see `config/schema.cue` for details)
cluster:
name: k0s-hands-on
nodes:
- name: node-1
qemu:
disk: 2147483648
memory: 1073741824
vcpus: 1
role: controller
ssh:
host: node-1
keyPath: ~/.ssh/id_rsa
proxy:
host: libvirt
user: libvirt
user: node
- name: node-2
role: worker
qemu:
disk: 8589934592
memory: 536870912
vcpus: 1
ssh:
host: node-2
keyPath: ~/.ssh/id_rsa
proxy:
host: libvirt
user: libvirt
user: node
- name: node-3
role: worker
qemu:
disk: 8589934592
memory: 536870912
vcpus: 1
ssh:
host: node-3
keyPath: ~/.ssh/id_rsa
proxy:
host: libvirt
user: libvirt
user: node