Test k0s and K3s using LXD

Try k0s and K3s on a LXD playground

Published on updated on

This post contains some ways to launch k0s and K3s. I have used LXD to create and configure system containers as hosts.

See the k-playground.sh script for an easy way to create and destroy LXD playgrounds.

This post is related to LXD Playground for Kubernetes post.

k0s - Test single node

Connect to a container and execute:

# get k0s
curl -sSLf https://get.k0s.sh | sudo sh

# install a "cluster" consisting of a single node
sudo k0s install controller --enable-worker

sudo systemctl start k0scontroller

# check if the service is running
systemctl status k0scontroller
# if there is an error, check the logs
# journalctl -xeu k0scontroller.service

# check the status of pods ...
watch 'sudo k0s kubectl get pods --all-namespaces'
# ... and wait for all pods tobe ready

# clean up
sudo systemctl stop k0scontroller
sudo k0s reset

k0s - Test k0sctl

Download k0sctl from Github - I have used v0.15.5 (latest at the time of this writting) - and make it executable.

#!/bin/bash

curl -sSLf https://github.com/k0sproject/k0sctl/releases/download/v0.15.5/k0sctl-linux-x64 -o k0sctl-linux-x64
curl -sSLf https://github.com/k0sproject/k0sctl/releases/download/v0.15.5/checksums.txt -o checksums.txt
if sha256sum --status --check --ignore-missing checksums.txt; then
    mv k0sctl-linux-x64 k0sctl
    chmod u+x k0sctl
    exit 0
fi
printf 'Check k0sctl-linux-x64 hash failed!\n'
exit 1

Create three containers then:

#!/bin/bash

adminUser='calin'
keyFile='/home/calin/keys/kTestKey'
ip10='10.70.10.10'
ip11='10.70.10.11'
ip20='10.70.10.20'

# add the key file
ssh-add "$keyFile"

# create the cluster bootstrap file
cat << EOF > k0sctl.yaml
apiVersion: k0sctl.k0sproject.io/v1beta1
kind: Cluster
metadata:
  name: k0s_test
spec:
  hosts:
  - role: controller
    ssh:
      address: "$ip10"
      user: "$adminUser"
      keyPath: "$keyFile"
  - role: controller
    ssh:
      address: "$ip11"
      user: "$adminUser"
      keyPath: "$keyFile"
  - role: worker
    ssh:
      address: "$ip20"
      user: "$adminUser"
      keyPath: "$keyFile"
EOF

# create the cluster
./k0sctl apply --config k0sctl.yaml

# generate a kubeconfig file
./k0sctl kubeconfig > kubeconfig

# copy the kubeconfig file to server0
scp kubeconfig "${adminUser}@${ip10}":

# check the pods ...
ssh "$ip10" sudo k0s kubectl get pods --kubeconfig kubeconfig -A
# ... or all resources
ssh "$ip10" sudo k0s kubectl get all --kubeconfig kubeconfig -A

Logs generated by k0sctl are in ~/.cache/k0sctl/k0sctl.log file.

K3s

Create three containers then:

kToken='keep_secret_this_token'
firstSrvIP='10.70.10.10'

# on first server run:
curl -sfL https://get.k3s.io | sh -s - server --token "$kToken" \
  --cluster-init

# on the second and third servers run:
curl -sfL https://get.k3s.io | sh -s - server --token "$kToken" \
  --server "https://${firstSrvIP}:6443" \

# (optional for simple tests, because in k3s any 'standard' server is also an agent, by default)
# on any worker node:
curl -sfL https://get.k3s.io | sh -s - agent --token "$kToken" \
  --server "https://${firstSrvIP}:6443"

# check the pods ...
ssh __any_server_IP_address__ -- sudo kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml get pods --all-namespaces
# ... or all resources
ssh __any_server_IP_address__ -- sudo kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml get all --all-namespaces

More information about k3s procedure can be found here:

Test deployment

If you want to do a quick deployment in Kubernets check Run a Stateless Application Using a Deployment