On November 07, 2016, Microsoft announced support for Kubernetes on Azure Container Service (preview). The integration of Kubernetes with Azure Container Service, consumer will be able to create a fully functional Kubernetes cluster that is integrated with the rest of your Azure resources.
To understand and develop capabilities of Kubernetes with ACS for development, I had to setup Kubernetes on my local windows 10 laptop. In this blog post, I am going to take you through setting up Minikube on your Windows 10 development machine and along the way I will share my experience. I would strongly recommend you go through some basic materials on ACS, Docker for Windows and Kubernetes concepts.
In general, solution like Kubernetes requires bit of efforts to setup the environment locally. Ideally, you need development environment which is like QA/staging and allow you to do your development on your laptop. This was the goal of Minikube project which helps you run Kubernetes on your development machine.
Pre-requisites for Development Machine Environment:
• VT-x/AMD-v virtualization must be enabled in BIOS (requires machine restart)
• Enable Hyper-V – go to Windows features On or Off, you will see dialog box with a list of Windows features as shown below. Navigate to the Hyper-V section and enable it (requires machine restart).
I prefer to use Hyper-V over VirtualBox to setup Kubernetes on my Windows machine because of its native windows support. The first step is to download Beta Channel Docker for Windows from here. Run Setup default configuration to Install Docker on your machine. Refer here if you need details about how to setup Docker on Windows 10 machine. Once you have successfully installed Docker, confirm deployment by typing “docker info” command in Command window as shown below.
Now, we will setup a new external network switch which will be used by our Hyper-V to setup the Kubernetes on local machine as described below.
o Make sure you have Ethernet connectivity while you are setting this.
o Open the Hyper-V manager.
o Select the Virtual Switch Manager on the left-side Actions panel.
o Set up a new external network switch to use instead of Docker NAT network switch (for Moby), which is set up by default when you install Docker for Windows.
o For this example, we created a virtual switch called “My Virtual Switch”.
I would prefer to create one default Docker machine by using command
docker-machine create --driver hyperv default
The next step is to download the latest Minikube binary from here and place that in the root folder of C drive. You may think why do you want to place binary in OS drive. This is because there is a bug in the Minikube which does not allow to install the local cluster if it is place anywhere other than C drive or in OS drive. Refer here for more details about bug. The file name is minikube-windows-amd64.exe. Rename this exe as “minikube” (just for simplicity).
Download the Kubectl command line utility from here and copy this alongside the kubectl.exe file from the previous section. We are all set now to launch a local Kubernetes one node cluster. Launch the PowerShell in Administrator mode and navigate to the drive where you have copied kubectl.exe and minikube.exe.
Let’s do standard testing to validate Minikube deployment by finding the version of Minikube and supported Kubernetes version as shown below. Go to %HOMEPATH%\.minikube folder and you will notice several folders are created. Have a look!
PS C:\> .\minikube.exe version
minikube version: v0.14.0
PS C:\> .\minikube get-k8s-versions
The following Kubernetes versions are available:
There are multiple commands that Minikube supports. You can use ‘–help’ option to see the list of commands.
Start Kubernetes Cluster locally
We are now ready to launch our Kubernetes cluster locally and we use start command for it. Before we start the cluster, we will check available flags/options via the help options and will use few of them. We want to use Kubernetes version v1.5.2 and VM driver is hyperv. If you would like to add more memory to local Kubernetes cluster, I would recommend using memory flag. Make sure you define hyperv-virtual-switch flag which should point to the external network switch you have created previously. We are also going to use couple of global flags like –v=7 and –alsologtostderr to see what is going on under the hood.
PS C:\> .\minikube.exe start --help Usage: minikube start [flags] Flags: –container-runtime string The container runtime to be used –cpus int Number of CPUs allocated to the minikube VM (default 2) –disk-size string Disk size allocated to the minikube VM (format: , where unit = b, k, m or g) (default “20g”) –docker-env stringArray Environment variables to pass to the Docker daemon. (format: key=value) –extra-config ExtraOption A set of key=value pairs that describe configuration that may be passed to different components. The key should be ‘.’ separated, and the first part before the dot is the component to apply the configuration to. Valid components are: kubelet, apiserver, controller-manager, etcd, proxy, scheduler. –host-only-cidr string The CIDR to be used for the minikube VM (only supported with Virtualbox driver) (default “192.168.99.1/24”) –hyperv-virtual-switch string The hyperv virtual switch name. Defaults to first found. (only supported with HyperV driver) –insecure-registry stringSlice Insecure Docker registries to pass to the Docker daemon –iso-url string Location of the minikube iso (default “https://storage.googleapis.com/minikube/minikube-0.7.iso”) –kubernetes-version string The kubernetes version that the minikube VM will use (ex: v1.2.3) OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64) (default “v1.5.1”) –kvm-network string The KVM network name. (only supported with KVM driver) (default “default”) –memory int Amount of RAM allocated to the minikube VM (default 2048) –network-plugin string The name of the network plugin –registry-mirror stringSlice Registry mirrors to pass to the Docker daemon –vm-driver string VM driver is one of: [virtualbox hyperv] (default “virtualbox”)Global Flags:
–alsologtostderr log to standard error as well as files
–log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
–log_dir string If non-empty, write log files in this directory (default “”)
–logtostderr log to standard error instead of files
–show-libmachine-logs Whether or not to show logs from libmachine.
–stderrthreshold severity logs at or above this threshold go to stderr (default 2)
–test.bench string regular expression per path component to select benchmarks to run
–test.benchmem print memory allocations for benchmarks
–test.benchtime duration approximate run time for each benchmark (default 1s)
–test.blockprofile string write a goroutine blocking profile to the named file after execution
–test.blockprofilerate int if >= 0, calls runtime.SetBlockProfileRate() (default 1)
–test.count n run tests and benchmarks n times (default 1)
–test.coverprofile string write a coverage profile to the named file after execution
–test.cpu string comma-separated list of number of CPUs to use for each test
–test.cpuprofile string write a cpu profile to the named file during execution
–test.memprofile string write a memory profile to the named file after execution
–test.memprofilerate int if >=0, sets runtime.MemProfileRate
–test.outputdir string directory in which to write profiles
–test.parallel int maximum test parallelism (default 4)
–test.run string regular expression to select tests and examples to run
–test.short run smaller test suite to save time
–test.timeout duration if positive, sets an aggregate time limit for all tests (default 0s)
–test.trace string write an execution trace to the named file after execution
–test.v verbose: print additional output
-v, –v Level log level for V logs
–vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Here is the command which we will execute to start the local Kuberenetes cluster.
.\minikube.exe start --kubernetes-version="v1.5.2" --vm-driver="hyperv" --memory=1024 --hyperv-virtual-switch="My Virtual Switch" --v=7 --alsologtostderr
On success, you will get the messaging stating “Kubectl is now configured to use the cluster.”
Let us understand what it is doing behind the scene.
o It generates the certificates and provision local Docker host which creates VM inside the Hyper-V.
o The host is provisioned with the boot2docker.iso and setup it up.
o At the end, it configures the Kubectl to use the local Kubernetes cluster.
You can check the status of the local cluster using status command.
PS C:\> .\minikube.exe status
Use the kubectl CLI to get the cluster information. In case you see the error like “.\kubectl : error: couldn’t read version from server:”, then you need to probably set the context again. The command for that is .\kubectl config set-context minikube
PS C:\> .\kubectl cluster-info Kubernetes master is running at https://192.168.1.101:8443 KubeDNS is running at https://192.168.1.101:8443/api/v1/proxy/namespaces/kube-sy stem/services/kube-dns kubernetes-dashboard is running at https://192.168.1.101:8443/api/v1/proxy/names paces/kube-system/services/kubernetes-dashboard
Minikube is a work in progress at this moment and it does not support all the features of Kubernetes. Refer here to know what is supported today. Hope this blog post gets you started with Kubernetes on your Windows development machine by using minikube. Please let me know your experience.
If you are interested in Kubernetes in Azure, please see Azure Container Service: https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough
In next post, we’ll look at how to deploy container application in Kubernetes development machine.