loading...
Cover image for Set up a Kubernetes cluster using microk8s on macOS

Set up a Kubernetes cluster using microk8s on macOS

reybis profile image Reybis Ceballos ・3 min read

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 https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

βš™οΈ 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

  NAME          STATUS   ROLES    AGE     VERSION
  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
                     provider=kubernetes
  Annotations:       <none>
  Selector:          <none>
  Type:              ClusterIP
  IP:                10.152.183.1
  Port:              https  443/TCP
  TargetPort:        16443/TCP
  Endpoints:         192.168.64.4:16443
  Session Affinity:  None
  Events:            <none>

Mine is 192.168.64.4.

πŸš€ Deploy a Pod

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

  kubectl create -f https://raw.githubusercontent.com/reybis/set-up-kubernetes-cluster/master/nginx-deployment.yml

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.

Posted on by:

reybis profile

Reybis Ceballos

@reybis

Oracle OCP, Solutions Architect, DevOps Engineer, Senior Project Manager #OCI | #AWS | #GCP | #OrclApex | #iOS | #Xamarin prinsoft.do excellotech.com

Discussion

pic
Editor guide