Deploy Lightweight Kubernetes with MicroK8s and Snap

Posted on 205 views

Kubernetes is the most trending word in the sphere of Containerization and Microservices. But deploying Kubernetes can be expensive, mostly when not being done to power production applications. In this tutorial, I’ll introduce you to MicroK8s tool which enables you to run the latest stable upstream Kubernetes release in Snap.

Production deployment: Deploy Production Kubernetes Cluster with Ansible & Kubespray

For Docker users: How To run Local Kubernetes clusters in Docker

MicroK8s is just a single package of k8s that installs on most Linux flavors and any other system which can run Snap. This is fit for running on IoT devices such as Raspberry Pi, personal computers and Desktops.

This deployment is not recommended for Production setups but only for offline development, prototyping, testing, or use it on a VM as a small, cheap, reliable k8s for CI/CD.

Features of MicroK8s – (

  • Fast install – Get a full Kubernetes system running in under 60 seconds.
  • Small – Use MicroK8s in your CI/CD pipelines and get on with your day without headaches.
  • Secure – Runs safely on your laptop with state of the art isolation.
  • Complete – Includes a docker registry so you can make containers, push them, and deploy them all on your laptop.
  • Upgrades – When a new major version comes out, upgrade with a single command (or automatically).
  • Featureful – Cool things you probably want to try on a small, standard K8s are all built-in. Just enable them and go.
  • GPU Passthrough – Give MicroK8s a GPGPU and your Docker containers can get all nice and CUDA.
  • Upstream – CNCF binaries delivered to your laptop, with updates and upgrades.

Setup Requirements

  • Linux Operating system – Debian, Ubuntu, CentOS, RHEL, Fedora, Arch e.t.c
  • Snap installed
  • User with sudo

Step 1: Install Snapd

We have guides on installation of Snapd:

Install Snap on Ubuntu/DebianCentOS 7FedoraArch Linux/Manjaro.

Step 2: Install MicroK8s

After installing Snap, you can start MicroK8s installation using Snap. Snaps are frequently updated to match each release of Kubernetes.

sudo snap install microk8s --classic

Installation should look like this:


All Published version can be checked with:

snap info microk8s

Once MicroK8s is installed, it will start creating a one node Kubernetes cluster. Status for this deployment can be checked using.

# microk8s.status 
microk8s is running
 jaeger: disabled
 fluentd: disabled
 gpu: disabled
 storage: disabled
 registry: disabled
 ingress: disabled
 dns: disabled
 metrics-server: disabled
 prometheus: disabled
 istio: disabled
 dashboard: disabled

From the output, we can see is MicroK8s is running and the state of addons available.

To check cluster info, use:

# microk8s.kubectl cluster-info
Kubernetes master is running at

Also get status of k8s node.

# microk8s.kubectl get nodes
microk8s   Ready       5m17s   v1.14.0

If you’re not comfortable with microk8s.kubectl command, you can create an alias for it.

echo "alias kubectl='microk8s.kubectl'" >>~/.bashrc
source ~/.bashrc

Then you can use kubectl command:

# kubectl  get nodes -o wide
microk8s   Ready       10m   v1.14.0            Ubuntu 18.04.2 LTS   4.15.0-45-generic   containerd://1.2.5

Enable/Disable Kubernetes Addons on MicroK8s

Addons available for MicroK8s are:

  • dashboard: Deploy kubernetes dashboard as well as grafana and influxdb.
  • dns: Deploy kube dns
  • storage: Create a default storage class. This storage class makes use of the hostpath-provisioner pointing to a directory on the host. Persistent volumes are created under $SNAP_COMMON/default-storage.
  • ingress: Create an ingress controller.
  • istio: Deploy the core Istio services. Use the microk8s.istioctl command to manage your deployments.
  • registry:  Deploy an image private registry and expose it on localhost:32000
  • metrics-server: Deploy the Metrics Server.
  • prometheus: Deploy the Prometheus Operator v0.25.
  • fluentd: Deploy Elasticsearch-Kibana-Fluentd logging and monitoring solution.
  • jaeger: Deploy the Jaeger Operator v1.8.2 in the “simplest” configuration.

You can enable and disable addons available for Kubernetes.

Enable Addons

Use the microk8s.enable command to enable addons.

# microk8s.enable dashboard dns
Enabling dashboard
secret/kubernetes-dashboard-certs created
serviceaccount/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/kubernetes-dashboard created
service/monitoring-grafana created
service/monitoring-influxdb created
service/heapster created
deployment.extensions/monitoring-influxdb-grafana-v4 created
serviceaccount/heapster created
configmap/heapster-config created
configmap/eventer-config created
deployment.extensions/heapster-v1.5.2 created
dashboard enabled
Enabling DNS
Applying manifest
service/kube-dns created
serviceaccount/kube-dns created
configmap/kube-dns created
deployment.extensions/kube-dns created
Restarting kubelet
DNS is enabled

Enable Storage addon:

# microk8s.enable storage
Enabling default storage class
deployment.extensions/hostpath-provisioner created created
Storage will be available soon

To enable Storage and Istio addons:

# microk8s.enable istio

The same format apply for other plugins. Confirm enabled addons with:

# microk8s.status
microk8s is running
 jaeger: disabled
 fluentd: disabled
 gpu: disabled
 storage: enabled
 registry: enabled
 ingress: disabled
 dns: disabled
 metrics-server: disabled
 prometheus: disabled
 istio: disabled
 dashboard: enabled

For more information like URL, use:

microk8s.kubectl cluster-info



Disable Addons

Use microk8s.disable command to disable addon.

# microk8s.disable istio
Disabling Istio
namespace "istio-system" deleted
Istio is terminating

Deploying Pods and Containers on MicroK8s

Deployments are done in standard Kubernetes way. See the example below which will create Nginx deployment with two containers.

# microk8s.kubectl run nginx --replicas 2 --image nginx
deployment.apps/nginx created

# microk8s.kubectl get deployments
nginx   2/2     2            2           39s

# microk8s.kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7db9fccd9b-7662b   1/1     Running   0          61s
nginx-7db9fccd9b-87z6d   1/1     Running   0          61s

Expose service:

# microk8s.kubectl expose deployment nginx --port 80 --target-port 80 \ 
  --type ClusterIP --selector=run=nginx --name nginx
service/nginx exposed

# microk8s.kubectl get services
kubernetes   ClusterIP            443/TCP   27m
nginx        ClusterIP           80/TCP    104s

Delete Deployment

# microk8s.kubectl delete deployment nginx
deployment.extensions "nginx" deleted

# microk8s.kubectl delete service nginx
service "nginx" deleted

Stopping and Restarting MicroK8s

You can easily shutdown MicroK8s when not in use without un-installing it.

# microk8s.stop

Start MicroK8s using:

# microk8s.start

Removing MicroK8s

If you wish to completely remove MicroK8s, first stop all running pods.


Then remove MicroK8s snap.

snap remove microk8s



MicroK8s is the quickest and most lightweight Kubernetes deployment tool available. It is ideal for playing with Kubernetes without mastery of Linux and Containers concepts before you can get started. For more reading, visit MicroK8s Documentation page.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.