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:-
- 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.
- 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.
- K3S
K3s is a highly available, certified Kubernetes distribution designed for production workloads. The most important it is "Lightweight Kubernetes"
- K3D
K3d is a lightweight wrapper to run k3s in docker.
- 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
Enable systemctl
in your WSL edit /etc/wsl.conf
sudo nano /etc/wsl.conf
add the following line:
[boot]
command="/usr/libexec/wsl-systemd"
then close the terminal and restart WSL with the following command in your PowerShell
wsl --shutdown
then you can start new WSL shell and check that systemctl is working
ps aux
note that first line(PID 1) is systemctl
then check systemctl status:
systemctl status
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
for the rest:
- comment out the line in the
/etc/fstab
:
#LABEL=cloudimg-rootfs / ext4 discard,errors=remount-ro 0 1
- 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=
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
- Switch to legacy iptables
update-alternatives --config iptables
select iptables-legacy
- package repository configuration
First, temporarily set some OS-specific variables:
. /etc/os-release
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
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
- Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io
- Add user to Docker group
sudo usermod -aG docker $USER
Finally, close that WSL window, and launch WSL again. And check if docker is working:
docker run --rm hello-world
Install K3D and AutoK3s
- Install K3D
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
- 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
Make it executable
chmod 755 ~/bin/autok3s
then add to path
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
- 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
start autok3s
to deploy Kubernetes cluster
autok3s serve
Open 127.0.0.1:8080 on your browser to start create, delete modify Kubernetes clusters.
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
You can add the explorer to the cluster
Top comments (0)