---
title: "MicroK8s on Ubuntu : A Getting Started Guide"
description: "Looking for lightweight, fast, and highly-available Kubernetes? In this tutorial learn to install MicroK8s on Ubuntu!"
canonical: "https://adamtheautomator.com/microk8s/"
---

# MicroK8s on Ubuntu : A Getting Started Guide

> Looking for lightweight, fast, and highly-available Kubernetes? In this tutorial learn to install MicroK8s on Ubuntu!

Source: https://adamtheautomator.com/microk8s/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![MicroK8s on Ubuntu : A Getting Started Guide](https://adamtheautomator.com/wp-content/uploads/2022/01/Getting-Started-with-MicroK8s-on-Ubuntu.jpg)

# MicroK8s on Ubuntu : A Getting Started Guide

[![](https://secure.gravatar.com/avatar/ff757e22f03c8a84ce8a2b8f87c53481ba627afec8bd1c8fda5c576097ea027c?s=192&d=mm&r=g)Joseph Eshiett](https://adamtheautomator.com/author/joseph-eshiett/)6 January 20225 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Kubernetes](/tag/kubernetes/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing Microk8s](#installing-microk8s)
*   [Adding Your User Account to the MicroK8s Group](#adding-your-user-account-to-the-microk8s-group)
*   [Enabling and Accessing the Kubernetes Dashboard](#enabling-and-accessing-the-kubernetes-dashboard)
*   [Deploying a Sample Application Microk8s](#deploying-a-sample-application-microk8s)
*   [Stopping, Starting, and Removing MicroK8s](#stopping-starting-and-removing-microk8s)
*   [Conclusion](#conclusion)

Are you looking for lightweight, fast, and highly-available Kubernetes? [**Microk8s**](https://microk8s.io/) might be what you need. High availability is in MicroK8s DNA. Once you install it, you rarely have to make modifications because everything just works out of the box.

If you’re still on the fence, read on! Because in this tutorial, you will learn step-by-step how to install Microk8s locally on Ubuntu so you can quickly get started with your first deployment!

## **Prerequisites**

This article will be a step-by-step tutorial. To follow the examples, you will need to have a [Ubuntu 20.04 LTS](https://ubuntu.com/download/desktop) computer, which already comes with the [**Snap package manager**](https://snapcraft.io/docs/installing-snapd) pre-installed.

Feel free to use other Linux distros, but note that you may need to install the Snap package manager separately.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## **Installing Microk8s**

Now that you have the prerequisites, your environment should be ready for the Microk8s installation. Luckily, Canonical has made the installation quick and convenient as a [Snap](https://snapcraft.io/about) package.

A Snap is a self-contained package that works universally on any Linux distribution with the Snap package manager.

To install on Ubuntu, follow these steps.

1\. Open a terminal session on your Ubuntu machine, whether locally or via [SSH](https://adamtheautomator.com/ssh-chrome-extension/).

Related:[How to Set up the SSH Google Chrome Extension](https://adamtheautomator.com/ssh-chrome-extension/)

2\. Run the following command on the terminal to install it.

```bash
# Installing the latest Microk8s version via snap
sudo snap install microk8s --classic
```

The image below shows the confirmation message after a successful installation. As you can see, the latest stable version as of this writing is v1.22.4.

![Successfully installed Microk8s](https://adamtheautomator.com/wp-content/uploads/2022/01/image-29.png)

Successfully installed Microk8s

3\. Lastly, to confirm the service status, run the following command.

```bash
# Checking Microk8s status
sudo microk8s status
```

The screenshot below confirms that the `microk8s` service is running. Additionally, you can see that the `ha-cluster` add-on is enabled by default, which provides high availability configuration on the current node.

![Displaying the microk8s service status](https://adamtheautomator.com/wp-content/uploads/2022/01/image-30.png)

Displaying the microk8s service status

Related:[Controlling Systemd services with Ubuntu systemctl](https://adamtheautomator.com/ubuntu-systemctl/)

## Adding Your User Account to the MicroK8s Group

Running the commands requires superuser privileges, which means you have to issue every command with `sudo`. To avoid this annoyance, the installation creates a group aptly named `microk8s`, where members will have superuser rights to run its commands.

1\. To add your user account, run the following command in the terminal.

```bash
# Adding the current user to Microk8s group
sudo usermod -aG microk8s $USER
```

2\. Adding your account does not automatically apply the new privileges on your current terminal session. To refresh your terminal session and the new privileges to take effect, run the below commands next.

```bash
# Re-entering user session for group update to take effect
su - $USER
# Reload the mircok8s group users
newgrp microk8s
```

3\. From this point, when you run `microk8s` commands, you no longer have to prefix the `sudo` command. To test, run the `microk8s kubectl` commands in the terminal.

```bash
# Getting available nodes
microk8s kubectl get nodes
# Displaying all contents in all the namespaces
microk8s kubectl get all -A
```

The commands should execute without requiring the `sudo` command, as you can see below.

![Running microk8s commands without sudo](https://adamtheautomator.com/wp-content/uploads/2022/01/image-31.png)

Running microk8s commands without sudo

> _The `kubectl` subcommand controls the Kubernetes cluster manager. If you prefer to drop the_ `microk8s` prefix and just use `*kubectl` to issue commands to Kubernetes, create an alias by running the command: `alias kubectl='microk8s kubectl'`.

## Enabling and Accessing **the Kubernetes Dashboard**

It supports a wide range of add-ons. One of which is the `dashboard` add-on that enables the Kubernetes web-based dashboard. The dashboard allows viewing and interacting with the resources using a GUI. What’s even better, enabling this add-on only takes a one-liner.

1\. Run the command below to enable the Kubernetes web dashboard.

```bash
# Enabling Kubernetes web dashboard
microk8s enable dashboard
```

![Enabling the Kubernetes dashboard](https://adamtheautomator.com/wp-content/uploads/2022/01/image-32.png)

Enabling the Kubernetes dashboard

2\. Next, get the IP address of the `kubernetes-dashboard` service, which is the dashboard IP address.

```bash
# Displaying services running in the kube-system namespace
microk8s kubectl get services --namespace kube-system
```

After running the command, take note of the IP address and the port number from the result.

![Getting the Kubernetes dashboard IP address](https://adamtheautomator.com/wp-content/uploads/2022/01/image-33.png)

Getting the Kubernetes dashboard IP address

3\. Accessing the dashboard requires authorization using the default token. To retrieve the default token, run the commands below.

```bash
# Get the default token name
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
# Display the token value
microk8s kubectl -n kube-system describe secret $token
```

As you can see below, the default token name is `default-token-7dqgd`. The default token name is unique on every installation.

Make sure to copy the token value. You’ll authenticate to the dashboard using this token in the succeeding steps.

![Retrieving the default token](https://adamtheautomator.com/wp-content/uploads/2022/01/image-34.png)

Retrieving the default token

4\. Open a new browser window and navigate to the dashboard’s IP address you copied in step #2.

5\. On the **Kubernetes Dashboard** sign-in page, paste the token value you copied in step #3 into the **Enter token** field and click **Sign in**.

![Signing in to the dashboard using a token ](https://adamtheautomator.com/wp-content/uploads/2022/01/image-35.png)

Signing in to the dashboard using a token

And you now have a graphical view of the Kubernetes resources.

![Viewing the Kubernetes Dashboard](https://adamtheautomator.com/wp-content/uploads/2022/01/image-36.png)

Viewing the Kubernetes Dashboard

> _To get a comprehensive list of add-ons, you can check out the [**Official Documentat**](https://microk8s.io/docs/addons)**[i](https://microk8s.io/docs/addons)**[**on**](https://microk8s.io/docs/addons)._

Related:[How to Install and Set Up Kubernetes Dashboard \[Step by Step\]](https://adamtheautomator.com/kubernetes-dashboard/)

## **Deploying a Sample Application Microk8s**

As long as you’ve followed the previous sections properly, you should now have a proper Kubernetes setup. This tutorial isn’t complete without you deploying a sample application for testing.

For this section, you will be deploying a base **[NGINX](https://www.nginx.com/)** application running in a Docker container.

Related:[Getting Started with NGINX on Docker](https://adamtheautomator.com/nginx-on-docker/)

> _A [**Kubernetes deployment**](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) is a way for Kubernetes to create, modify, and manage [**pods**](https://kubernetes.io/docs/concepts/workloads/pods/). Deployments are responsible for managing the desired state of pods._

1\. Run the command below to create a deployment called `nginx`. This command pulls an **NGINX** image from **[Docker Hub](https://hub.docker.com/_/nginx)**, creates a pod, and runs an NGINX container inside the pod.

```bash
# Creating deployment for nginx
microk8s kubectl create deployment nginx --image=nginx
```

The results below confirm that you’ve created the deployment successfully.

![Creating an NGINX deployment](https://adamtheautomator.com/wp-content/uploads/2022/01/image-37.png)

Creating an NGINX deployment

2\. Next, run the command below to confirm if the pod for NGINX is running.

```bash
# Displaying available pods
microk8s kubectl get pods
```

As you can see below, you now have one pod running.

![Listing running pods](https://adamtheautomator.com/wp-content/uploads/2022/01/image-38.png)

Listing running pods

3\. While the pod running NGINX is currently active and healthy, the NGINX container inside the pod is not accessible from the host machine. To expose the application to the network, run the command below to bind the container’s port 80 to the host machine’s port 80.

```bash
# Creating service for nginx deployment and assigning nodeport
microk8s kubectl create service nodeport nginx --tcp=80:80
```

As you can see below, the result indicates that the command has created a [service](https://kubernetes.io/docs/concepts/services-networking/service/) for the NGINX deployment. A Kubernetes service allows network communication between pods or between pods and the host machine.

![Creating a service for the deployment](https://adamtheautomator.com/wp-content/uploads/2022/01/image-39.png)

Creating a service for the deployment

4\. Before you can access the NGINX container using your browser, you first need to find its port number. To do so, run the command below to get the `nginx` pod port number.

```bash
microk8s kubectl get svc nginx
```

In this example, the node port Kubernetes mapped on the machine for the `nginx` container is 31979.

![Finding the service port number](https://adamtheautomator.com/wp-content/uploads/2022/01/image-40.png)

Finding the service port number

Now, open a browser window and navigate to _`http://<host-ip>:<port>`_. If you’re accessing the container from the host, the URL would be _`http://localhost:31979`_.

![Accessing the NGINX app running inside the pod](https://adamtheautomator.com/wp-content/uploads/2022/01/image-41.png)

Accessing the NGINX app running inside the pod

Related:[How To Serve NGINX Subdomains or Multiple Domains](https://adamtheautomator.com/nginx-subdomain/)

## **Stopping, Starting, and Removing MicroK8s**

Running Kubernetes in the background consumes system resources. If you’re not using the service, consider stopping the service to free up resources and save power. Whether you’re starting, stopping, or uninstalling, you’ll only need to execute one-liners — isn’t that convenient?

To stop, run the below command.

```bash
# Stopping Microk8s
microk8s stop
```

Execute the command below when you need to start Microk8s and its services again for further testing.

```bash
# Starting Microk8s
microk8s start
```

But if you no longer need and wish to uninstall it from your computer, run the removal command below.

```bash
# Uninstalling microk8s
sudo snap remove microk8s
```

## **Conclusion**

Finally, you have come to the end of this tutorial. With the above walk-through, you have successfully installed Microk8s locally, started a single node, deployed a sample application into a cluster, and successfully stopped the cluster.

Now, what will you do next? How about adding another Microk8s node to your cluster? But it’s entirely up to you! Go crazy with it!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fmicrok8s%2F&text=MicroK8s%20on%20Ubuntu%20%3A%20A%20Getting%20Started%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fmicrok8s%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fmicrok8s%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Effortless-Storage-Management-With-Kubernetes-PVC.jpg)

### [Kubernetes PVC for Data Reliability: A Comprehensive Guide](/kubernetes-pvc/)

Tired of Kubernetes storage headaches? Discover how Kubernetes PVC simplifies data persistence and ensures your applications stay up and running.

![](https://adamtheautomator.com/wp-content/uploads/2024/01/kustomize.jpg)

### [A Beginners Guide to Kubernetes Kustomize](/kustomize/)

Dive into Kubernetes Kustomize to master dynamic deployments — A beginner’s guide for personalized configurations and seamless adaptability!

![](https://adamtheautomator.com/wp-content/uploads/2022/06/How-to-Keep-Kubernetes-Secrets-Safe.jpg)

### [Kubernetes Secrets Management: Enhance Safety & Reliability](/kubernetes-secrets/)

Explore expert techniques for securing Kubernetes secrets in production with this guide. Learn to enhance safety and reliability in your Kubernetes deployments.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
