Part 2 – Kubernetes MiniKube Environment on Mac OS
I tend to use my Macbook for development these days, windows is still a good environment, and I still maintain a Win10 VM on my Mac using Parallels – but find myself using it less and less. With the advent of Rider as a cross-platform IDE, and .net core, I spend more time in my Mac OS now.
One other benefit of the Mac OS environment is the ease of setting up Docker, VirtualBox, and MiniKube – the Kubernetes development environment. Setting it up on Windows 10 using Hyper-V is possible, but non-trivial, and has the side effect of not being able to run the native Docker daemon side-by side.
When learning to use Kubernetes, one of the biggest benefits is the local single-cluster development environment call MiniKube, it allows you to completely test your k8s deployment scripts and definitions on your mac, and these same definitions (with a slight bit of tweaking) will work in the same way when deployed to an Azure Container Services cluster (or your own IaaS K8S environment).
These instructions are for Mac OS, Windows 10 guides exist and are not wildly different, but I will go into detail for Windows 10 in a later article.
– Check your Virtualisation is enabled in the BIOS
Open a terminal – and execute the following command:
sysctl -a | grep machdep.cpu.features | grep VMX
If the command doesn’t error and you get some output – then you are good to go! =]
– Install Prerequisites
Make sure you have homebrew installed…
brew update && brew install kubectl && brew cask install docker minikube virtualbox
What have we just done? We have installed Kubectl (The Kubernetes CLI), and installed a triumvirate of tools to support the creation of MiniKube locally. Docker, MiniKube and VirtualBox.
– Verify Installation
We can execute a few commands to ensure that everything installed O.K (the terminal will tell you if there were errors anyway). As long as you get good output from the following commands, we should be O.K to continue.
kubectl version --client
– Start MiniKube
To start a local MiniKube cluster, which will default to using 2GB of memory, execute the following command and wait for the Host VM to download and setup on VirtualBox.
This can take time, especially on a slower internet connection, or slightly older Macbook, but once finished you should get a message to the terminal indicating that MiniKube has been setup, and that the kubectl cli is configured to use the MiniKube context. A Kubernetes single-node cluster is now running inside the VM on your mac host. Nice =]
– Check out K8S
Lets checkout to see if we can see the minikube node, execute the following command (see here for the Kubectl readme)
kubectl get nodes
You should see an output similar to
NAME STATUS ROLES AGE VERSION
minikube Ready <none> 40s v1.7.5
– Ensure Docker daemon from MiniKube is used
You can start executing docker commands in the terminal now, as docker itself was installed by Brew, however something that might be confusing at first (especially if you were to deploy a pre-built container into MiniKube straight away) is when you execute a command such as ‘docker ps’ to view current containers, you will see the host machine context view, e.g. containers outside of the MiniKube context, which resides inside the VirtualBox VM.
We need to switch to this context to view, and manipulate containers running inside MiniKube. Execute the following command:
eval $(minikube docker-env)
Now executing docker commands will use the correct context, try it out before moving on, you should see the some of the MiniKube related containers running.
– Create a local image registry
Kubernetes will need to pull container images from a registry when instructed to do so via definition files, if your files contain references to images on Dockerhub, or a private registry then this step wouldn’t be needed as long as you are also publishing directly to there too, but for local development we may as well have a local registry, so execute the following command:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
That’s it – if the above has all gone well you should be able to run the following command and load up the MiniKube dashboard:
Now we will be ready to start creating a local multi-container application. I will cover this in the next article in the series.
Have fun =]