How to Setup Kubernetes Cluster with Microk8s: Microk8s is a small, lightweight, and fully compatible Kubernetes distribution from Canonical. It’s a minimalistic distribution focused on simplicity and performance. Given its footprint, Microk8s can be easily deployed in IoT and edge devices.
Canonical has packaged Microk8s as a snap, the company’s package manager for Linux. A snap is a bundle of an app and its dependencies that works without modification across many different Linux distributions. Snaps are independent, self-contained applications that run in a sandbox with mediated access to the host system. Snaps have emerged as an alternative to the standard .deb packages typically used in Debian-based distributions. Applications packaged as a snap can be easily installed and uninstalled.
Along with recent versions of Ubuntu, snaps can be deployed on a variety of platforms, including Linux Mint, Raspberry Pi OS, and Arch Linux.
Installation
MicroK8s is available on Linux, Windows, and macOS. A graphical Windows installer is offered on the project’s website. macOS users should use Brew while Linux users are served by snaps.
Let’s check how to install the Microk8s using snap on Ubuntu VM, for this test, we are using Ubuntu 18.04 LTS version, note: all these commands ran using root user.
If you want to install latest version please use following commands,
# snap install microk8s --classic
If you want to install specific version, you should use –channel to call the release,
# snap install microk8s --classic --channel=1.18/stable
With this, version of MicroK8s that’s based on Kubernetes v1.18.
Setup Cluster
MicroK8s bundles its own version of the Kubectl command-line tool. Use microk8s kubectl to interact with your cluster, appending a regular kubectl command:
# microk8s kubectl get all --all-namespaces
This is as like kubectl in k8s. Just add microk8s front of kubectl command and run here, it should get as like same result.
Now, lets try to deploy a pod and see how it goes.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- name: http
containerPort: 80
protocol: TCP
Apply the manifest to your cluster:
# microk8s kubectl apply -f ./nginx.yaml
MicroK8s will create a new Pod running the NGINX web server. It’ll show up when you re-run
# microk8s kubectl get po# microk8s kubectl config view --raw > $HOME/.kube/config
This exports the MicroK8s connection information into your Kubernetes configuration file, allowing plain kubectl commands to reach your cluster.
Most MicroK8s commands require superuser access. For long-term use, add your user account to the microk8s group so you don’t need to use sudo each time:
# usermod -aG microk8s $USER
Docker Images
Please note, MicroK8s can’t access your local Docker images automatically from the system. If you wish to deploy a pod from local image, you should manually import it to the MicroK8s registry by exporting it as a tar archive.
Follow this command this compress the local docker image,
# docker save my-image:latest > my-image.tar
Use this command to export the image to microk8s
# microk8s ctr image import my-image.tar
Now you can deploy the pod with your image. You can list all known images in the MicroK8s registry with the microk8s ctr images ls command.
Please continue read on: How to Setup Kubernetes Cluster with Microk8s — FoxuTech