Using minikube instead of Docker Desktop on Mac OS

With the recent license changes on Docker Desktop, many users have switched to minikube on Mac. minikube is simple to setup and run, and also gives you kubernetes. Everyone should be using kubernetes.

This assumes the user is using brew for package management and that Docker Desktop has been removed.

# install hyperkit and minikube
brew install hyperkit
brew install minikube

# install the docker CLI tools
brew install docker
brew install docker-compose

# start minikube and setup the docker commands
minikube start
eval $(minikube docker-env)

After this installation, docker commands should work as before, but now they run on minikube. Also, be sure to install the kubernetes-cli package via brew to take advantage of kubernetes.

Test out the new setup with a simple docker command:

> docker run --rm -it ruby:3.1
irb(main):001:0> puts "hello, world!"
hello, world!
=> nil                                           
irb(main):002:0> 

Now, let’s test a simple kubernetes pod. This example will use the ruby:3.1 image, with the following pod.yaml:

apiVersion: v1
kind: Pod 
metadata:
  name: ruby
spec:
  containers:
  - name: ruby
    image: ruby:3.1
    command: ['ruby', '-e', 'puts "Hello, Kubernetes!"']

Deploy the pod to minikube with the following kubectl command:

kubectl apply -f pod.yaml

Next, verify that it ran, printing “Hello, Kubernetes!” to the log:

> kubectl logs ruby
Hello, Kubernetes!

When finished, cleanup the ruby container. Since I don’t have any other stopped containers, I will use docker system prune to cleanup all stopped containers, (and some other items):

> docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
bac129e82aa2b20f36228be60df63369dc2cf2e27453f0f2f7c0a21ab6478e95

Total reclaimed space: 0B

Also, be sure to cleanup the kubernetes pod:

> kubectl delete -f pod.yaml
pod "ruby" deleted

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *