The Rancher k3s project has made it possible to run Kubernetes Clusters on Edge and IoT devices with ease. K3s provides an easy way to run a Lightweight Kubernetes cluster with half the memory, all in a binary of less than 100 MB. Alpine Linux on the other side is a Lightweight operating system that has gained lots of traction in microservices space.

This guide will help you setup a Lightweight Kubernetes cluster on Alpine Linux with k3s. If you want to try this in a Lab, checkout our guide on using Vagrant.

How To Run Alpine Linux with Vagrant

Setup Kubernetes on Alpine Linux with k3s

k3s is installed through a bash script that performs all the actions in the background without user input. Open the console of your Alpine Linux and run the command below.

$ curl -sfL | sudo sh -

Command execution output:

[INFO]  Finding release for channel stable
[INFO]  Using v1.18.2+k3s1 as release
[INFO]  Downloading hash
[INFO]  Downloading binary
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/
[INFO]  Creating uninstall script /usr/local/bin/
[INFO]  env: Creating environment file /etc/rancher/k3s/k3s.env
[INFO]  openrc: Creating service file /etc/init.d/k3s
[INFO]  openrc: Enabling k3s service for default runlevel
[INFO]  openrc: Starting k3s
 * Caching service dependencies ...                                                                                                               [ ok ]
 * Mounting cgroup filesystem ...                                                                                                                 [ ok ]
 * Starting k3s ...                                                                                                                               [ ok ]

Confirm a list of running services:

$ rc-status
Runlevel: default
 crond                                                                                                                                     [  started  ]
 acpid                                                                                                                                     [  started  ]
 haveged                                                                                                                                   [  started  ]
 net-online                                                                                                                                [  started  ]
 k3s                                                                                                                           [  started 00:01:22 (0) ]
 qemu-guest-agent                                                                                                                          [  started  ]
 sshd                                                                                                                                      [  started  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
 sysfs                                                                                                                                     [  started  ]
 fsck                                                                                                                                      [  started  ]
 root                                                                                                                                      [  started  ]
 localmount                                                                                                                                [  started  ]
 cgroups                                                                                                                                   [  started  ]
Dynamic Runlevel: manual

Check Cluster nodes status:

$ sudo kubectl get nodes
myalpine   Ready    master   2m14s   v1.18.2+k3s1

View cluster config:

$ sudo kubectl cluster-info 
Kubernetes master is running at
CoreDNS is running at
Metrics-server is running at

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Notice that a kubeconfig file is written to /etc/rancher/k3s/k3s.yaml and additional utilities, such as kubectl, crictl,, and are added by default.

$ sudo crictl ps
CONTAINER           IMAGE               CREATED             STATE               NAME                     ATTEMPT             POD ID
c422071177c71       aa764f7db3051       2 minutes ago       Running             traefik                  0                   dce7e443a00d3
00a260c8ca596       897ce3c5fc8ff       2 minutes ago       Running             lb-port-443              0                   8396062f10e99
f8cee92686f79       897ce3c5fc8ff       2 minutes ago       Running             lb-port-80               0                   8396062f10e99
a24528e2b6d48       c4d3d16fe508b       2 minutes ago       Running             coredns                  0                   4ab79ffe4b375
a928d07727c8a       9dd718864ce61       3 minutes ago       Running             metrics-server           0                   06052271c42cf
5708f0490b3ef       9d12f9848b99f       3 minutes ago       Running             local-path-provisioner   0                   1a91feb1e22d1

Add additional nodes to the Cluster

To install on worker nodes we should pass:

  • K3S_URL
  • K3S_TOKEN or K3S_CLUSTER_SECRET environment variables

You can locate the K3S_TOKEN at /var/lib/rancher/k3s/server/node-token on your server:

$ sudo cat /var/lib/rancher/k3s/server/node-token

The command to add additional node will look similar to this:

curl -sfL | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX sh -

How To Uninstall k3s on Alpine Linux

If you want to remove k3s on your Alpine Linux machine, run the command:

$ sudo

Sample execution output:

+ iface=vethad0f82d8
+ '[' -z vethad0f82d8 ]
+ ip link delete vethad0f82d8
+ read ignore iface ignore
+ iface=veth3b5de91e
+ '[' -z veth3b5de91e ]
+ ip link delete veth3b5de91e
+ read ignore iface ignore
+ iface=veth99b636ef
+ '[' -z veth99b636ef ]
+ ip link delete veth99b636ef
+ read ignore iface ignore
+ ip link delete cni0
+ ip link delete flannel.1
+ rm -rf /var/lib/cni/
+ iptables-restore
+ grep -v CNI-
+ grep -v KUBE-
+ iptables-save
+ which systemctl
+ which rc-update
+ rc-update delete k3s default
 * service k3s removed from runlevel default
+ rm -f /etc/init.d/k3s
+ rm -f /etc/rancher/k3s/k3s.env
+ trap remove_uninstall EXIT
+ '[' -L /usr/local/bin/kubectl ]
+ rm -f /usr/local/bin/kubectl
+ '[' -L /usr/local/bin/crictl ]
+ rm -f /usr/local/bin/crictl
+ '[' -L /usr/local/bin/ctr ]
+ rm -f /usr/local/bin/ctr
+ rm -rf /etc/rancher/k3s
+ rm -rf /var/lib/rancher/k3s
+ rm -rf /var/lib/kubelet
rm: can't remove '/var/lib/kubelet': Resource busy
+ rm -f /usr/local/bin/k3s
+ rm -f /usr/local/bin/
+ remove_uninstall
+ rm -f /usr/local/bin/

Visit project documentation page for more reading.