To setup a Kubernetes cluster, there are several options available, each with its own advantages and use cases. Below are some of the most popular methods for installing Kubernetes:
Minikube: A local Kubernetes cluster that is easy to set up and ideal for development and testing purposes.
kubeadm: A tool that provides a simple way to create a Kubernetes cluster on any machine
k3s: A lightweight Kubernetes distribution designed for edge computing and IoT devices.
microk8s: A minimal Kubernetes distribution that is easy to install and suitable for development and testing.
In this guide, I will use k3s for the installation process. However, the steps may vary slightly depending on the method you choose. Always refer to the official documentation for the specific installation method you decide to use.
k3s is a lightweight Kubernetes distribution that is designed to be easy to install and operate. It is ideal for edge computing, IoT devices, and development environments.
1
Install Script
The easiest way to install k3s is to use the installation script provided by the k3s project. You can run the following command in your terminal:
curl -sfL https://get.k3s.io | sh -
This command will download and execute the installation script, which will set up k3s, its dependencies, and kubectl on your machine.
Make sure you have curl installed on your system before running the above command.
Terminal Output
kcserver@kcserver:~$ curl -sfL https://get.k3s.io | sh -[sudo] password for kcserver: [INFO] Finding release for channel stable[INFO] Using v1.34.6+k3s1 as release[INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.34.6%2Bk3s1/sha256sum-amd64.txt[INFO] Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.34.6%2Bk3s1/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 unitCreated symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.[INFO] systemd: Starting k3s
2
Verify Installation
After the installation is complete, you can verify that k3s is running by checking the status of the service:
If you encounter a permission issue when running kubectl commands (e.g., kubectl get nodes), it may be because the k3s installation creates a kubeconfig file that is owned by root. To fix this issue, you can change the ownership of the kubeconfig file to your user.
Issue
kcserver@kcserver:~$ kubectl get nodesWARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode or --write-kubeconfig-group to modify kube config permissionserror: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
To resolve this, run the following command to change the ownership of the kubeconfig file: