Set up a Kubernetes cluster using Minikube on macOS
Tags: kubernetes, devops, macos, microservices
Published: 2020-08-17 17:56:40

**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 **minikube**. 

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. [Minikube](#-minikube)
1. [Prerequisites](#-prerequisites)
2. [Installation](#-installation)
3. [Create the cluster](#-create-the-cluster)
4. [Test Kubernetes](#-test-kubernetes)
5. [See the Cluster IP](#-see-the-cluster-ip)
6. [Deploy a Pod](#-deploy-a-pod)

<a href="#minikube"></a>

### 💠 Minikube
**Minikube** is a tool that runs a single-node Kubernetes cluster in a virtual machine on your computer, so basically, it wouldn't be for a production environment. Remember, this is for **test/dev purposes**.

<a name="#prerequisites"></a>

### ☑️ Prerequisites 

Before starting, you need these prechecks:
  * Check if virtualization is supported on your system
    _In terminal run the following command, and verify that the output is non-empty:_
    ```toml
    sysctl -a | grep -E --color 'machdep.cpu.features|VMX'
    ```
    _If the output is not empty, we can proceed._

  * An Hypervisor, in macOS you can use hyperkit or [Virtualbox](https://www.virtualbox.org/).
    _For this post's goal, we would stay with [Virtualbox](https://www.virtualbox.org/) to maintain simplicity and hence is cross-platform. I'm a big fan of vagrant to make this kind of environment but it would be overwhelming for the tutorial, maybe for another day 😉._

  * At least 20G of disk space and 4G of memory is recommended.
  * A system that supports virtualization.
  * An internet connection.

<a name="#installation"></a>

### ⚙️ Installation

Open terminal and run the following commands.

1. Install Minikube with brew.
    ```toml
    brew install minikube
    ```
    Install Minikube without brew.
    <pre>
    curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 \ && chmod +x minikube
    sudo mv minikube /usr/local/bin
    </pre>

2. Confirm Installation of Minikube.
    ```toml
    minikube status
    ```

<a name="#create-the-cluster"></a>

### 🧑‍🚀 Create the cluster 

1. To deploy a **Kubernetes cluster**, just start minikube with the driver parameter set to `virtualbox`.
  ```toml
  minikube start --driver=virtualbox
  ```

2. Enable the DNS service.
  ```toml
  minikube addons enable kube-dns
  ```

<a name="#test-kubernetes"></a>

### ✅ Test Kubernetes 

Let's test our command center
  ```toml
  kubectl get nodes
  ```
  _You should see one node in status Ready_

<a name="#see-the-cluster-ip"></a>

### 🗺️ See the Cluster IP 

Run the following command and find the cluster IP in the endpoint property.
  ```toml
  kubectl describe svc kubernetes
  ```

<a name="#deploy-a-pod"></a>

### 🚀 Deploy a Pod 

I make a definition file just for you, Time to make a simple cluster:
  ```toml
  kubectl create -f https://raw.githubusercontent.com/reybis/tutorial-minikube/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.