Install MicroK8s on macOS

Key Value
Summary Get a local Kubernetes on MacOS with Microk8s and Multipass.
Categories containers
Difficulty 1
Author Ammar Naqvi ammar.naqvi@canonical.com, Konstantinos Tsakalozos kos.tsakalozos@canonical.com

Overview

What is Kubernetes

Kubernetes clusters host containerised applications
in a reliable and scalable way. Having DevOps in mind, Kubernetes makes
maintenance tasks such as upgrades dead simple.

What is MicroK8s

MicroK8s is a CNCF certified upstream Kubernetes deployment that runs entirely on your workstation or edge device.
Being a snap it runs all Kubernetes services natively (i.e. no virtual machines) while packing the entire set of libraries and binaries needed. Installation is limited by how fast you can download a couple
of hundred megabytes and the removal of MicroK8s leaves nothing behind.

In this tutorial you’ll learn how to…

  • Install Homebrew on macOS
  • Install Multipass and MicroK8s from Brew
  • Run MicroK8s add-ons

You will only need …

  • A machine with macOS with at least 8GB of RAM

Install Homebrew

Duration: 3:00

Open a terminal and run the installer:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

This will download and execute the installer for Homebrew on your Mac.

Install MicroK8s

Duration: 4:00

With Homebrew installed, you can now use it to install the pre-packaged version
of MicroK8s. This is achieved in two stages.

First run the command:

brew install ubuntu/microk8s/microk8s

This will download and install a version of Multipass, a VM system for running
Ubuntu and other packages required by MicroK8s.

The second stage is to initialise the MicroK8s environment, This is done by
running the microk8s command which was added to your system in the
previous step:

microk8s install --channel=1.26

You can also use this command to install or switch to a different channel, for example, to switch the version of Kubernetes:

microk8s install --channel=1.25

asciicast

Wait for MicroK8s to start

Duration: 2:00

MicroK8s will run all the components necessary to set up and run a full
Kubernetes environment. On some systems, this can take a minute or two. We
can check when the system is ready by running:

microk8s status --wait-ready

Access Kubernetes

Duration: 2:00

MicroK8s bundles its own version of kubectl for accessing Kubernetes. Use it
to run commands to monitor and control your Kubernetes. For example, to view your node:

microk8s kubectl get nodes

…or to see the running services:

microk8s kubectl get services

Deploy an app

Duration: 3:00

Of course, Kubernetes is meant for deploying apps and services. You can use
the kubectl command to do that as with any Kuberenetes. Try
installing a demo app:

microk8s kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

Note: For m1-based macs you will need an image that supports that architecture

It may take a minute or two to install, but you can check the status:

microk8s kubectl get pods

Use add-ons

Duration: 2:00

MicroK8s uses the minimum of components for a pure, lightweight Kubernetes.
However, plenty of extra features are available with a few keystrokes using
“add-ons” – pre-packaged components that will provide extra capabilities
for your Kubernetes, from simple DNS management to machine learning with
Kubeflow!

To start it is recommended to add DNS management to facilitate communication
between services. For applications which need storage, the ‘storage’ add-on
provides directory space on the host. These are easy to set up:

microk8s enable dns 
microk8s enable storage

Starting and Stopping MicroK8s

Duration: 1:00

MicroK8s will continue running until you decide to stop it. You can stop and
start MicroK8s with these simple commands:

microk8s stop

… will stop MicroK8s and its services. You can start again any time by running:

microk8s start

You can also just reinitialise your Kubernetes with microk8s reset.

Congratulations!

Duration: 1:00

You now have your own Kubernetes, ready to deploy apps or experiment with.

Next steps

1 Like

Hi, trying to install microk8s and enable Kubeflow on a MacBook Pro 16" intel, MacOs.
I did “brew install ubuntu/microk8s/microk8s”, which worked and installed version 1.22.

The Kubeflow documentation states I need to use microk8s version 1.21.
How would I brew install that particular version, as “brew install ubuntu/microk8s/microk8s@1.21” isn’t valid.
Or perhaps there is a way to run version 1.21 once I installed microk8s as per these instructions?

(My MacOs (Darwin) doesn’t support snap install, so I can’t select a snap channel.)

Hey there! Thanks for the question. In order to get K8s 1.21, all you need to do is:

brew install ubuntu/microk8s/microk8s
microk8s install --channel 1.21

If you’re planning to run Kubeflow, I’d also recommend using the --cpu and --mem flags with microk8s install in order to give the VM as much RAM and CPU as you can spare.

1 Like

Thanks!
So simple, should have figured it out.
Thanks for the tip too

FYI - the Google Kubernetes Bootcamp image isn’t available for aarch64, so as a result this step in the tutorial will fail for users on M1+ Macs (which is probably a large percent of the late 2022 audience for an article on installing microk8s on macOS). Solution would be to either bother Google to build an appropriate architecture release of the Bootcamp image or to use a different demonstration deployment.

1 Like