Multipass and MicroK8s: the Quickest Route to Ubuntu and Kubernetes?
Would your Kubernetes-based workflows run better on Multipass and MicroK8s?
Join the DZone community and get the full member experience.Join For Free
In my recent interview with Carmine Rimi of Canonical, he mentioned Multipass and MicroK8s as alternatives to Docker for running Kubernetes-based workflows on a development machine. As a long-term user of Docker for Desktop (Mac), I was intrigued to see what alternatives it might offer.
I’m a macOS user, so fired up homebrew to first install Multipass, but snaps are available, and binaries for Windows:
brew cask install multipass
Next, you can search for images with the
find command which returns a list of the available images (four at the time of writing):
To launch the most up to date image, use the
multipass launch ubuntu command, or to specify a version, replace “ubuntu” with a version from the
find output above, or an image URL. For example, to launch Ubtunu 16.04, use
multipass launch 16.04.
Then to connect to a running instance. First, find its instance name with the
list option, and then use the
shell option, specifying the image. For example:
$ multipass list
Name State IPv4 Image
close-willet Running 192.168.64.4 Ubuntu 16.04 LTS
rewarded-stud Running 192.168.64.3 Ubuntu 18.04 LTS
multipass shell rewarded-stud
You can also run commands in an instance indirectly without connecting directly to the instance with the
exec option, and the command separated with a double dash (
--), for example:
multipass exec rewarded-stud -- ls -a
Then stop and delete an instance with the
delete options respectively:
multipass stop rewarded-stud
multipass delete rewarded-stud
This still leaves a few remnants behind, to completely remove all deleted instances and images, use
Here’s where things get interesting. There’s no additional package to install on your host machine (if you’re running macOS or Windows), you install MicroK8s as a snap on your Multipass-hosted Ubuntu instance.
Connect to an instance as detailed above, then run the following inside the instance:
sudo snap install microk8s --classic
Then start MicroK8 with:
Alternatively, start MicroK8 without connecting to the instance using:
multipass exec intrigued-kudu -- /snap/bin/microk8s.start
OK, great, but this is fiddly from the host machine, it would be preferable to use something like kubectl.
First, you need to add the multipass user to the microk8s group, so it has permissions to run and access the services needed:
multipass exec intrigued-kudu -- sudo usermod -a -G microk8s multipass
Next, copy the kubeconfig file from the instance:
multipass exec intrigued-kudu -- /snap/bin/microk8s.config > kubeconfig
Then use the new config to access Kubernetes running on the instance:
kubectl --kubeconfig=kubeconfig get all --all-namespaces
You can see what services are running on the Kubernetes cluster with:
$ multipass exec intrigued-kudu -- /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
CoreDNS 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
Replace “127.0.0.1” with the IP of the VM, and you should be able to access services as usual.
From Development to Production
So far, so good, but what benefit does this bring over any existing workflow you may have already? Canonical argues that multipass gives you access to the same images they supply to cloud providers, giving you a consistent environment from development to production. There are other ways to find and use these images with other tools, and many may argue that they don’t need that consistency.
If you’re happy to add another tool alongside (or instead of) anything else you are using (and only need Ubuntu images), then Multipass uses minimal CPU and disk space and guarantees you reliable images that match more than 30% of those used on the cloud.
Opinions expressed by DZone contributors are their own.