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.
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 https://get.k3s.io | sudo sh -
Command execution output:
[INFO] Finding release for channel stable
[INFO] Using v1.30.6+k3s1 as release
[INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.30.6+k3s1/sha256sum-amd64.txt
[INFO] Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.30.6+k3s1/k3s
[INFO] Verifying binary download
[INFO] Installing k3s to /usr/local/bin/k3s
[INFO] Skipping installation of SELinux RPM
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s.service
[INFO] systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO] systemd: Starting k3s
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
Update Kubeconfig.
mkdir ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube
Check Cluster nodes status:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
debian11 Ready control-plane,master 3m12s v1.30.6+k3s1
View cluster config:
$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
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, k3s-killall.sh, and k3s-uninstall.sh are added by default.
$ sudo crictl ps
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD
d96c07ed6821c d1e26b5f8193d 2 minutes ago Running traefik 0 00e45d39e0b3b traefik-64f55bb67d-2cp2d
2d17a35292a86 af74bd845c4a8 2 minutes ago Running lb-tcp-443 0 87d680ba3caf3 svclb-traefik-6d969a65-fg76s
47dde809f9297 af74bd845c4a8 2 minutes ago Running lb-tcp-80 0 87d680ba3caf3 svclb-traefik-6d969a65-fg76s
14fa95c8b3ebb 817bbe3f2e517 3 minutes ago Running metrics-server 0 49534c917316d metrics-server-648b5df564-8pkqc
724b0db29d7b0 b29384aeb4b13 3 minutes ago Running local-path-provisioner 0 1be802bad6ec4 local-path-provisioner-957fdf8bc-rwlnh
5beb4abc00bd0 ead0a4a53df89 3 minutes ago Running coredns 0 7c552a2d58d4a coredns-77ccd57875-wn86p
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
K102a068f91219cd8647bb55815bd2e6734afaa513562ed47b47d1d14000a3eea35::server:2021cc18e3e53df19c2ee830cddda0a5
The command to add additional node will look similar to this:
curl -sfL https://get.k3s.io | 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 k3s-uninstall.sh
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
/sbin/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/k3s-killall.sh
+ remove_uninstall
+ rm -f /usr/local/bin/k3s-uninstall.sh
Visit project documentation page for more reading.
Explore More with CloudSpinx
Looking to streamline your tech stack? At CloudSpinx, we deliver robust solutions tailored to your needs:
- Hosting Services: Web Hosting, VPS, and Email Hosting
- Development Services: Custom Web & Mobile Apps, UI/UX Design
- Consultancy Services: Cloud, DevOps, Cybersecurity, and Kubernetes Experts
- Managed Services: End-to-end infrastructure support
- Dedicated Servers: Power and control, fully managed
Learn more about how we can support your journey with CloudSpinx.