So at the moment, I am doing a few things, such as:
- Reading a good Scala book
- Reading another book on CATS type level programming for Scala
- Looking into Azure Batch
- Deciding whether I am going to make myself learn GoLang (which I probably will)
Amongst all of that, I have also decided that I am going to obligate myself to writing a small series of posts of Kubernetes. The rough guide of the series might be something like shown below:
- What is Kubernetes / Installing Minikube (this post)
- What are pods/labels, declaring your first pod
- ConfigMaps/Secrets
- Services
- Singletons (such as a DB)
- Deployments
So yeah, that is the rough guide of what I will be doing. I will most likely condense all of this into a single www.codeproject.com article at the end too, as I find there is a slightly different audience for articles than there is for blog posts.
So What is Kubernetes?
Kubernetes (The name Kubernetes originates from Greek, meaning helmsman or pilot, and is the root of governor and cybernetic) is an open-source system for automating deployment, scaling, and management of containerized applications.
It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best-of-breed ideas and practices from the community.
Kubernetes builds upon previous ventures by Google such as Borg and Omega, but it also uses the current container darling Docker, and is a free tool.
Kubernetes can run in a variety of ways, such as:
- Managed cloud service (AWS and Azure both have container services that support Kubernetes out of the box)
- On bare metal where you have a cluster of virtual machines (VMs) that you will install Kubernetes on (see here for really good guide on this)
- Minikube – Running a very simple SINGLE node cluster on your own computer (I will be using this for this series just for its simplicity and cost savings)
So without further ado, we will be starting this series with a simple introduction, of how to install Kubernetes locally using Minikube.
Installing Minikube
I am using a Windows PC, so these instructions are biased towards Windows development where we will be using Hyper-V instead of VirtualBox. But if you prefer to use VirtualBox, I am sure you can find out how to do the specific bits that I talk about below for Hyper-V in VirtualBox.
Ok so let's get started.
Installing Docker
The first thing you will need to do is grab Docker from here (I went with the stable channel). So download and install that. This should be a fairly vanilla install. At the end, you can check the installation using 2 methods.
Checking your system tray Docker icon.
And trying a simple command in PowerShell (if you are using Windows):
Ok, so now that Docker looks good, let's turn our attention to Hyper-V. As I say, you could use VirtualBox, but since I am using Windows, Hyper-V just seems a better more integrated choice. So let's make sure that is turned on.
Setup Hyper-V
Launch Control Panel –> Programs and Features.
Then we want to ensure that Hyper-V is turned on, we do this by using the “Turn Windows features on or off”, and then finding Hyper-V and checking the relevant checkboxes.
Ok, so now that you have Hyper-V enabled, we need to launch Hyper-V Manager and add a new Virtual Switch (we will use this Switch name later when we run Minikube). We need to add a new switch to provide isolation from the Virtual Switch that Docker sets up when it installs.
So once Hyper-V Manager launches, create a new “External” Virtual Switch.
Which you will need to configure like this:
Installing Minikube
Ok, now what we need to do is grab the minikube binary from github. The current releases are maintained here: https://github.com/kubernetes/minikube/releases
You will want to grab the one called minikube-windows-amd64
as this blog is a Windows installation guide. Once downloaded, you MUST copy this file to the root of C:\. This needs to be done due to a known bug (read more about it here: https://github.com/kubernetes/minikube/issues/459).
Just for your own sanity, rename the file c:\minikube-windows-amd64 to c:\minikube.exe or brevity when running commands.
Installing kubectrl.exe
Next, you will need to download kubectrl.exe which you can do by using a link like this, where you would fill the link with the version you want. For this series, I will be using v1.9.0 so my link address is: http://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/windows/amd64/kubectl.exe. Take this kubectrl.exe and place it alongside your minikube.exe in C:\.
Provisioning the Cluster
Now that we have the basic setup, and required files, we need to test our installation. But before that, it is good to have a look at the minikube.exe commands/args which are all documented via a command like this which you can run in PowerShell.
The actual command we are going to use is as follows:
.\minikube.exe start --kubernetes-version="v1.9.0" --vm-driver="hyperv"
--memory=1024 --hyperv-virtual-switch="Minikube Switch" --v=7 --alsologtostderr
You may be wondering where some of these values come from. Well, I have to admit it is not that clear from the command line –help text you see above. You do have to dig a bit. Perhaps the most intriguing ones above are
vm-driver
hyperv-virtual-switch
These instruct minikube to use HyperV and also to use the new HyperV Manager switch we set up above.
Make sure you get the name right. It should match the one you setup.
You can read more about the HyperV command args here: https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperV-driver
Anyway, let's get back to business where we run this command line (I am using PowerShell in Administrator mode). We should see some output like this, where it eventually ends up with some like the hightlight section.
This does a few things for you behind the scenes:
- Creates a Docker Vm which is run in HyperV for you.
- The host is provisioned with boot2docker.iso and set up.
- It configures kubectrl.exe to use the local cluster.
Checking Status
You can check on the status of the cluster using the following command like:
Stale Context
If you see this sort of thing:
You can fix this like this:
Verifying Other Aspects
The final task to ensure that the installation is sound is to try and view the cluster info and dashboard, like this:
This should bring up a web UI:
So that is all looking good.
So that’s it for this post, I will start working on the next ones very soon… stay tuned!