MicroK8s can be used to run Kubernetes on Mac for testing and developing apps on macOS.
MicroK8s is the local distribution of Kubernetes developed by Ubuntu. It’s a compact Linux snap that installs a single node cluster on a local PC. Although MicroK8s is only built for Linux, Kubernetes on Mac works by setting up a cluster in an Ubuntu VM.
It runs all Kubernetes services natively on Ubuntu and any operating system (OS) which supports snaps. This is beneficial for testing and building apps, creating simple Kubernetes clusters and developing microservices locally – essentially all dev work that needs deployment.
MicroK8s provides another level of reliability because it provides the most current version of Kubernetes for development. The latest upstream version of Kubernetes is always available on Ubuntu within one week of official release.
Kubernetes and MicroK8s both need a Linux kernel to work and require an Ubuntu VM as mentioned above. Mac users also need Multipass, the tool for launching Ubuntu VMs on Mac, Windows and Linux.
Here are instructions to set up Multipass and to run Kubernetes on Mac.
Install a VM for Mac using Multipass
- The latest Multipass package is available on GitHub. Double click the .pkg file to install it.
- To start a VM with MicroK8s run:
Make enough resources available for hosting. Below, we’ve created a VM named microk8s-vm and given it 4GB of RAM and 40GB of disk.
multipass launch --name microk8s-vm --mem 4G --disk 40G
multipass exec microk8s-vm -- sudo snap install microk8s --classic
multipass exec microk8s-vm -- sudo iptables -P FORWARD ACCEPT
The VM has an IP that can be checked with the following: (Take note of this IP since our services will become available here).
Name State IPv4 Release
microk8s-vm RUNNING 192.168.64.1 Ubuntu 18.04 LTS
Interact with MicroK8s on the VM
This can be done in three ways:
- Using a Multipass shell prompt (command line) by running:
multipass shell microk8s-vm
- Using multipass exec to execute a command without a shell prompt by inputting:
multipass exec microk8s-vm -- /snap/bin/microk8s.status
- Using the Kubernetes API server running in the VM. Here one would use MicroK8s kubeconfig file with a local installation of kubectl to access the in-VM-kubernetes. Do this by running:
multipass exec microk8s-vm -- /snap/bin/microk8s.config > kubeconfig
Next, install kubectl on the host machine and then use the kubeconfig:
kubectl --kubeconfig=kubeconfig get all --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
Default service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 3m12s
Accessing in-VM Multipass services – enabling MicroK8s add-ons
A basic MicroK8s add-on to setup is the Grafana dashboard. Below we show one way of accessing Grafana to monitor and analyse a MicroK8s instance. To do this execute:
multipass exec microk8s-vm -- /snap/bin/microk8s.enable dns dashboard
DNS is enabled
Next, check the deployment progress by running:
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl get all --all-namespaces
Which should return output similar to:
Once all the necessary services are running, the next step is to access the dashboard, for which we need a URL to visit. To do this, run:
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:16443
Heapster is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Grafana is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
InfluxDB is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-influxdb:http/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
If we were inside the VM, we could access the Grafana dashboard by visiting: this URL But, we want to access the dashboard from the host (i.e. outside the VM). We can use a proxy to do this:
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl proxy --address='0.0.0.0' --accept-hosts='.*'
Starting to serve on [::][::]:8001
Leave the Terminal open with this command running and take note of the port (8001). We will need this next.
To visit the Grafana dashboard, we need to modify the in-VM dashboard URL by:
- Replacing the 127.0.0.1 with the VM IP address (multipass info microk8s-vm)
- Replacing the port (16443) with the proxy port: 8001 https://192.168.64.1:8001/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
- Enter this URL into your web browser and you should see the Grafana dashboard (below)
Kubernetes on Mac in summary
Building apps that are easy to scale and distribute has taken pride-of-place for developers and DevOp teams. Developing and testing apps locally using MicroK8s should help teams to deploy their builds faster.
- Kubernetes 1.15 now available from Canonical
- Install a local Kubernetes with MicroK8s – tutorial
- Multipass on Windows
- For CTOs: the no-nonsense way to accelerate your business with containers
- How to integrate Ubuntu with Microsoft Active Directory
- Install single node and multi node Kubernetes