Set up a Kubernetes cluster on macOS using microk8s

Featured image

Disclaimer: This post follows a simple approach, there are probably better ways to do this (please share them if you know any!), and your mileage most definitely will vary.

This post is part of a series of posts on how to Set up a Kubernetes cluster on macOS, in this case, using microk8s.

Kubernetes is a complex container orchestration tool that can be overwhelming for beginners. Had you wondered how to get started on Kubernetes by yourself easily without the complexity of Turnkey Solutions (Oracle OKE, AWS EKS) and Managed Solutions (Google GKE), this post would give you the simplicity to deploy a Kubernetes cluster on macOS intended for dev/test purposes.

Table of Contents

  1. Microk8s
  2. Prerequisites
  3. Installation
  4. Create the cluster
  5. Test Kubernetes
  6. See the Cluster IP
  7. Deploy a Pod

💠 Microk8s

Enter microk8s, it is the smallest, most straightforward production-grade cluster of K8s. There are no VMs in the middle like other deployments Minikube. Instead, it uses snap packages, snap is an application packaging and isolation technology; microk8s is so small than even you can use it on Raspberry Pi.

Although our goal is to deploy a dev/test environment, microk8s is intended for all 3 environments (production, dev & test). Whether you are running a production environment or interested in exploring K8s, microK8s serves your needs.

☑️ Prerequisites

Before starting, you need these prechecks:

  • Install the brew package manager.
  • At least 20G of disk space and 4G of memory is recommended.
  • An internet connection.

Don’t have the brew command? You need to open a terminal and run the following command:

/bin/bash -c "$(curl -fsSL"

⚙️ Installation

In terminal, install microk8s with brew.

brew install ubuntu/microk8s/microk8s

On macOS microk8s need multipass, when prompted say yes.

🧑‍🚀 Create the cluster

  1. To deploy a Kubernetes cluster, you can go with the install command without parameters.

    microk8s install

    Or you can be more specific like me (2 CPU, 2GB RAM, 30GB maximum space of disk).

    microk8s install --cpu 2 --mem 2 --disk 30

    While it is running, you can open another terminal window and check the installation’s status with the following command:

    microk8s status --wait-ready
  2. Enable the DNS service.

    microk8s enable dns

✅ Test Kubernetes

Let’s test our command center

kubectl get nodes

You should see one node named microk8s-vm in status Ready

microk8s-vm   Ready    <none>   4d19h   v1.18.6-1+64f53401f200a7

🗺️ See the Cluster IP

Run the following command and find the cluster IP in the endpoint property.

kubectl describe svc kubernetes
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
Port:              https  443/TCP
TargetPort:        16443/TCP
Session Affinity:  None
Events:            <none>

Mine is

🚀 Deploy a Pod

I make a definition file just for you, Time to make a simple cluster:

kubectl create -f

This will create a pod of nginx and one nodePort service at 30005.

Since you know the Cluster IP, you can see your nginx pod http://cluster-ip:30005 deployed on your new local cluster! 🎉

That’s it, now you have a Kubernetes cluster in your machine without VMs.

See also in Set up a Kubernetes cluster on macOS

comments powered by Disqus