Installing and Configuring Kubernetes with Docker on MacOS

Docker Containers

Install Kubernetes for MacOS

Installing Kubernetes (K8S) with Docker installed on my machine caused an error:

The connection to the server was refused – did you specify the right host or port?

I tried the following:

  • Installed manually via: curl -LO$(curl -s 
  • Installed via Homebrew: brew install kubernetes-cli

I found that installation of K8S can be done through Docker.  Do the following to automate the installation of K8S on your machine (mine is MacOS):

  • On MacOS menu bar, click on Docker.
  • Click: Preferences
  • Click: Kubernetes
  • Checkbox: Enable Kubernetes
  • Select Kubernetes
  • Click: Apply

The UI should look the following:

Kubernetes Section of Docker UI Configuration

Install Minikube

Do the following to use Homebrew to install Minikube:

Switch between Docker for Desktop or minikube by clicking on the Docker icon on the menu bar, hover to Kubernetes, and choose the driver.

Uninstall Minikube

The latest Docker for MacOS (Docker v18) comes with Kubernetes built-in and we don’t need to use Minikube for local development.  We can use docker-for-desktop! 🙂

  • brew cask uninstall minikube
  • kubectl config delete-context minikube

Switching Context

We can switch between Docker for Desktop (DFD) and Minikube with two ways. One way is through kubectl

  • Get a listing: kubectl config get-contexts
  • Switch to DFD: kubectl config use-context docker-for-desktop
  • Minikube: kubectl config use-context minikube

The alternative is using Docker for Desktop menu:

kubectl Commands

Some of the commands I use commonly on Kubernetes.

Apply yaml Configkubectl apply -f ./deployment.yaml
Export Portkubectl expose deployment tomcat-deployment –type=NodePort
Service Detailskubectl describe service/tomcat-deployment

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: