DEV Community

Cover image for Quickly create K3s cluster and add K3s nodes with GUI Tool using AutoK3s (Installation guide in WSL)
msh2050
msh2050

Posted on

Quickly create K3s cluster and add K3s nodes with GUI Tool using AutoK3s (Installation guide in WSL)

AutoK3s is a new tool that will make it easy to install and manage Kubernetes clusters in many platforms.
In this tutorial, we will install Kubernetes in windows WSL with the use of:-

  1. Ubuntu 22.04 WSL distro

What is amazing in this distro is that they have built in systemctl. If you chose another distro, you should use other methods to make docker and other services start.

  1. Docker for Linux (without docker desktop)

As you may know, docker desktop is not free anymore, and I found it use more resources from the pc.

  1. K3S

K3s is a highly available, certified Kubernetes distribution designed for production workloads. The most important it is "Lightweight Kubernetes"

  1. K3D

K3d is a lightweight wrapper to run k3s in docker.

  1. AutoK3s

AutoK3s is a lightweight tool for simplifying K3s cluster management.

Install a Linux distro

it is recommended to use Ubuntu 22.04 in this tutorial. You can download it from Microsoft store.

It is advisable to upgrade.

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Enable systemctl

in your WSL edit /etc/wsl.conf

sudo nano /etc/wsl.conf
Enter fullscreen mode Exit fullscreen mode

add the following line:

[boot]
command="/usr/libexec/wsl-systemd"
Enter fullscreen mode Exit fullscreen mode

then close the terminal and restart WSL with the following command in your PowerShell

 wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

then you can start new WSL shell and check that systemctl is working

 ps aux
Enter fullscreen mode Exit fullscreen mode

systemctl
note that first line(PID 1) is systemctl

then check systemctl status:

systemctl status
Enter fullscreen mode Exit fullscreen mode

for me, I got 3 failed services:

  • ssh.service
  • systemd-remount-fs.service
  • systemd-sysusers.service

to solve ssh service :

 apt-get install openssh-server openssh-client
 dpkg-reconfigure openssh-server
Enter fullscreen mode Exit fullscreen mode

for the rest:

  • comment out the line in the /etc/fstab:
#LABEL=cloudimg-rootfs   /        ext4   discard,errors=remount-ro       0 1
Enter fullscreen mode Exit fullscreen mode
  • open /usr/lib/systemd/system/systemd-sysusers.service and delete all lines, then add:
[Unit]
Description=Create System Users
Documentation=man:sysusers.d(5) man:systemd-sysusers.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=sysinit.target shutdown.target systemd-update-done.service
ConditionNeedsUpdate=/etc

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-sysusers
TimeoutSec=90

[Service]
LoadCredential=

Enter fullscreen mode Exit fullscreen mode

Finally, restart and check the services again.

Install Docker

the instructions for installing Docker in details from this tutorial, we can skip Sharing dockerd and adding script (because we use systemctl) in short this can be done with the following:

  • Install dependencies
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2
Enter fullscreen mode Exit fullscreen mode
  • Switch to legacy iptables
update-alternatives --config iptables
Enter fullscreen mode Exit fullscreen mode

select iptables-legacy

  • package repository configuration

First, temporarily set some OS-specific variables:

. /etc/os-release
Enter fullscreen mode Exit fullscreen mode

Then, make sure that apt will trust the repo:

curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo tee /etc/apt/trusted.gpg.d/docker.asc
Enter fullscreen mode Exit fullscreen mode

Then add and update the repo information so that apt will use it in the future:

echo "deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  • Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode
  • Add user to Docker group
sudo usermod -aG docker $USER
Enter fullscreen mode Exit fullscreen mode

Finally, close that WSL window, and launch WSL again. And check if docker is working:

 docker run --rm hello-world
Enter fullscreen mode Exit fullscreen mode

Install K3D and AutoK3s

  • Install K3D
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • Install AutoK3s Download the binary from the release page.
curl https://github.com/cnrancher/autok3s/releases/download/v0.5.1/autok3s_linux_amd64 --create-dirs -o ~/bin/autok3s
Enter fullscreen mode Exit fullscreen mode

Make it executable

chmod 755 ~/bin/autok3s
Enter fullscreen mode Exit fullscreen mode

then add to path

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • install kube-explorer (optional)
curl https://github.com/cnrancher/kube-explorer/releases/download/v0.2.9/kube-explorer-linux-amd64 --create-dirs -o ~/bin/kube-explorer

chmod 755 $HOME/bin/kube-explorer
Enter fullscreen mode Exit fullscreen mode

start autok3s to deploy Kubernetes cluster

autok3s serve
Enter fullscreen mode Exit fullscreen mode

Open 127.0.0.1:8080 on your browser to start create, delete modify Kubernetes clusters.

autok3s

Select k3d as provide and give name to the cluster and specify how many mater/worker nodes you want.

This is a sample option I used to build a cluster with one master node and one worker node and limit their ram usage to 1 GB
options

You can add the explorer to the cluster

explorer

Oldest comments (0)