In this guide, we will walk through the detailed steps to set up Kubernetes on a Mac. This includes installing the necessary tools, configuring your environment, and verifying the setup. Let’s get started!


Prerequisites

Before setting up Kubernetes on your Mac, ensure you have the following:

  • A Mac running macOS 10.15 (Catalina) or later.
  • Administrator access to install software.
  • Homebrew package manager installed.

Steps to Set Up Kubernetes on Mac

1 Install Homebrew

If Homebrew is not already installed, you can install it using the following command:

</>
Copy
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Explanation: This command downloads and installs Homebrew, for macOS. It simplifies the installation of various tools and dependencies needed for Kubernetes.

Set Up Kubernetes on Mac - Step 1: Install Homebrew on Mac

2 Install kubectl

The kubectl command-line tool is used to interact with Kubernetes clusters. Install it using Homebrew:

</>
Copy
brew install kubectl

Explanation: This command installs the official Kubernetes CLI tool. Once installed, you can use kubectl to manage your Kubernetes cluster and workloads.

Set Up Kubernetes on Mac - Step 2: Install kubectl

To verify the installation, run:

</>
Copy
kubectl version --client

This command displays the version of kubectl installed on your system.

3 Install Docker Desktop

Docker Desktop includes a built-in Kubernetes cluster, making it an excellent option for running Kubernetes locally. Download and install Docker Desktop for Mac from the official website:

Docker Desktop Download

Set Up Kubernetes on Mac - Step 3: Install Docker Desktop on Mac

Download based on your system configuration.

Open the Docker.dmg file.

Drag and drop the Docker into Applications.

Start the Docker Application.

Click Accept.

Click Finish.

Enter password if asked and click OK.

Click Allow.

Based on your requirement, choose Work or Personal and enter your email address, or you may Skip this step by clicking on the Skip link available at the top right corner.

The following is the Docker Desktop.

After installation, enable Kubernetes from Docker Desktop’s settings:

  • Open Docker Desktop.
  • Go to Settings > Kubernetes.
  • Check the box for Enable Kubernetes and click Apply & Restart.

A notification appears.

Click on Install. The docker starts pulling images.

4 Verify Kubernetes Cluster

Once Docker Desktop has started Kubernetes, verify the status of the Kubernetes cluster.

Open a Terminal and run the following command.

</>
Copy
kubectl cluster-info

Explanation: This command checks the status of the Kubernetes cluster and provides details about the master and DNS services.

Verify Kubernetes Cluster

5 Test Kubernetes with a Sample Application

Deploy a sample NGINX application to ensure Kubernetes is running correctly. Use the following command to create a deployment:

</>
Copy
kubectl create deployment nginx --image=nginx

Expose the deployment as a service to access it:

</>
Copy
kubectl expose deployment nginx --type=LoadBalancer --port=80

Check the running Pods and services using:

</>
Copy
kubectl get pods
kubectl get pods
</>
Copy
kubectl get services
kubectl get services

Access the application using the service’s external IP or localhost, depending on your setup.

Enter the url http://localhost in a browser window, and you would see the following.

6 Clean Up

To delete the resources created during the test, use the following commands:

</>
Copy
kubectl delete service nginx
kubectl delete service nginx
</>
Copy
kubectl delete deployment nginx

This removes the sample application and service from your Kubernetes cluster.


Congratulations! You have successfully set up Kubernetes on your Mac. You can now explore Kubernetes further by deploying more complex applications and experimenting with its powerful features.