Mastering Kubernetes on macOS: A Comprehensive Guide

Running Kubernetes on macOS: A Comprehensive Guide

macOS, with its Unix-based core and robust developer ecosystem, is an excellent platform for running Kubernetes. This guide will walk you through the process of setting up a local Kubernetes cluster on your macOS machine, using tools like Docker Desktop and kubectl.

Prerequisites

Before you start, ensure you have the following prerequisites installed on your macOS:

  • Homebrew: A popular package manager for macOS. If you don't have it, install it using the following command in your terminal: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Docker Desktop: Download and install Docker Desktop for macOS from the official Docker website.
  • Kubectl: The Kubernetes command-line tool. You can install it using Homebrew by running brew install kubectl.

Installing Minikube

Minikube is a tool that allows you to run Kubernetes locally. It's perfect for testing and developing Kubernetes applications. To install Minikube, run the following command in your terminal:

☕︎‧₊kubernetes٠࣪⋆💻₊˚ᵎ Devops
☕︎‧₊kubernetes٠࣪⋆💻₊˚ᵎ Devops

brew install minikube

Setting Up Minikube

Now that Minikube is installed, you can start it up with the following command:

minikube start

Kubernetes summerized in a minute
Kubernetes summerized in a minute

Minikube will download a virtual machine image, start it, and configure it to run your Kubernetes cluster. This process might take a few minutes.

Verifying Your Cluster

Once Minikube is up and running, you can verify that your cluster is ready by running the following command:

kubectl get nodes

Kubernetes
Kubernetes

You should see output similar to the following, indicating that your cluster has one node (the Minikube VM) and it's ready:

NAME STATUS ROLES AGE
minikube Ready control-plane,master 1m

Deploying Your First Application

Now that your cluster is up and running, you can deploy your first application. Let's deploy a simple NGINX deployment. Create a file named nginx-deployment.yaml with the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Then, apply this deployment using the following command:

kubectl apply -f nginx-deployment.yaml

You can verify that your deployment is running by checking the pods with the following command:

kubectl get pods

Accessing Your Application

To access your NGINX application, you'll need to port-forward the service to your local machine. First, create a service by creating a file named nginx-service.yaml with the following content:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Apply this service using the following command:

kubectl apply -f nginx-service.yaml

Now, port-forward the service to your local machine with the following command:

kubectl port-forward svc/nginx-service 8080:80

Finally, open your web browser and navigate to http://localhost:8080 to see your NGINX welcome page.

Kubernetes - Controladores mais utilizados
Kubernetes - Controladores mais utilizados
Elevating Performance and Scalability: The Docker and Kubernetes Advantage
Elevating Performance and Scalability: The Docker and Kubernetes Advantage
A few things I've learned about Kubernetes
A few things I've learned about Kubernetes
KUBERNETES SYSTEM
KUBERNETES SYSTEM
Sahn Lam on LinkedIn: What is Kubernetes?    Kubernetes (k8s) is a container orchestration…
Sahn Lam on LinkedIn: What is Kubernetes? Kubernetes (k8s) is a container orchestration…
Kubernetes (K8s) Explained in One Visual 🧠⚙️
Kubernetes (K8s) Explained in One Visual 🧠⚙️
🚀 Kubernetes Cheat Sheet ! | Nikhil Kolambikar posted on the topic | LinkedIn
🚀 Kubernetes Cheat Sheet ! | Nikhil Kolambikar posted on the topic | LinkedIn
Maximise Your Productivity: Harness Hot Reloading in Kubernetes
Maximise Your Productivity: Harness Hot Reloading in Kubernetes
¿Qué es Kubernetes? | Microsoft Azure
¿Qué es Kubernetes? | Microsoft Azure
the roadmap for kubernets is shown in this graphic, which shows how
the roadmap for kubernets is shown in this graphic, which shows how
Como configurar o Kubernetes com o Kubeadm no CentOS | SempreUpdate
Como configurar o Kubernetes com o Kubeadm no CentOS | SempreUpdate
Kubectl Cheat Sheet
Kubectl Cheat Sheet
an image of a document with the words, fundamentnal kubernets concept
an image of a document with the words, fundamentnal kubernets concept
A Beginner’s Guide to Kubernetes
A Beginner’s Guide to Kubernetes
Will Kubernetes Still Be Popular in 5-10 Years?
Will Kubernetes Still Be Popular in 5-10 Years?
the components of kubernets are labeled in red and blue, with arrows pointing to
the components of kubernets are labeled in red and blue, with arrows pointing to
the kubernets basics diagram with several different types of service and services in it
the kubernets basics diagram with several different types of service and services in it
What Is Kubernetes? K8s Architecture for Cloud-Native Networks
What Is Kubernetes? K8s Architecture for Cloud-Native Networks
Kubernetes monitoring with Prometheus, the ultimate guide | Sysdig
Kubernetes monitoring with Prometheus, the ultimate guide | Sysdig
Top 10 must-know Kubernetes design patterns | Red Hat Developer
Top 10 must-know Kubernetes design patterns | Red Hat Developer
Read the Latest Blogs from Nutanix
Read the Latest Blogs from Nutanix
the kubeadm logo is shown in blue and has a steering wheel on it
the kubeadm logo is shown in blue and has a steering wheel on it
Suresh Sharma on LinkedIn: Kubernetes architecture is based on a master-node design.  * Control…
Suresh Sharma on LinkedIn: Kubernetes architecture is based on a master-node design. * Control…