Kubernetes Local Development with Minikube on Hyper-V Windows 10

Ion Mudreac
5 min readJul 22, 2018

--

Most of the development recently is done online especial development that requires Kubernetes and cloud. In many cases when developers travel and don’t have reliable access to Internet is good to have local development environment that can be run on laptop and provide basic Kubernetes setup to continue development process in more productive way.

In this How-To article I show how minikube allows you to run functional Kubernetes as single node cluster on laptop in Windows 10 using Hyper-V Hypervisor.

Let’s start by Install and configure minikube with Grafana, Prometeus, Helm and Istio on Windows 10

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).

Hyper-V Installation

Hyper-V is included with Windows since Windows Server 2008 as well as Windows 8, 8.1 and 10 in the Pro versions. It can be enabled from Control Panel at “Turn Windows features on or off” under “Programs and Features”. Activate the “Hyper-V” checkbox, apply the change, and follow the directions on screen.

Network configuration

First, you must configure a new virtual switch so that your virtual machine will be able to connect to the Internet. Once Hyper-V is enabled, start the Hyper-V Manager.

Configuration can be done in GUI by opening Power Shell as Administrator and run Hyper-V Manager

mmc.exe virtmgmt.msc

Or we can use only Power Shell for the rest of the configurations.

Creating External switch

Using Power Shell (run as Administrator)

  • Get a list of the network adapters in the host. In a laptop you should typically see ‘Ethernet’ and ‘Wi-Fi’
Get-NetAdapter
  • Create the external switch with a name of VM-External-Switch, bound to the network adapter named Wi-Fi retrieved from the previous command. You may need to change your -NetAdapterName to interface connected to internet.
New-VMSwitch -name ExternalSwitch  -NetAdapterName "Ethernet 3"  -AllowManagementOS $true

The easiest way to install minikube is to deployed from choco

Chocolatey is a package manager for Windows (like apt-get or yum but for Windows). It was designed to be a decentralized framework for quickly installing applications and tools that you need. It is built on the NuGet infrastructure currently using Power Shell as its focus for delivering packages.

Follow Installation Guide or follow below PowerShell commands

Using PowerShell (run as Administrator)

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1'))

Using cmd (run as Administrator)

@”%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1'))" && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”

Once install check for any Upgrades available for Chocolatey

choco upgrade chocolatey

Install kubectl cli

choco install kubernetes-cli

Install minikube

Using PowerShell (run as Administrator)

choco install minikube
  • Test minikube installation
minikube version
  • Check available Version of Kubernetes
minikube get-k8s-versions
  • Update minikube
minikube update-check

Initiate minikube

Check available initialization options

minikube.exe start — help

Initialize Hyper-V VM with K8s deployed

minikube start — vm-driver hyperv — cpus 4 — memory=4096 — hyperv-virtual-switch “VM-External-Switch”
  • vm-driver Hyper-V. Specify Hypervisor driver to be used
  • cpus 4 Specify number of CPU “cores” allocation, If not specified “Default is 2”
  • memory=4096 Specify amount of RAM allocated, If not specified “Default is 2048”
  • hyperv-virtual-switch “VM-External-Switch” Specify virtual network swith to be used “VM-External-Switch was created in previous steps”
  • kubernetes-version string Specify version of kubernetes to be installed (ex. v1.2.3)

Post Install minikube

  • Stop minikube k8s VM
minikube stop
  • Disable Dynamic RAM allocation in Hyper V
Set-VMMemory minikube -DynamicMemoryEnabled $false
  • Start minikube k8s VM
minikube start

Deploy additional Kubernetes components

  • List minikube addons
minikube addons list
  • Enable Hipster for cluster performance monitoring
minikube addons enable heapster

Post Install checks minikube

minikube status
minikube service list
  • Lunch kubernetes dashboard
minikube dashboard
  • Check dashboard URL
minikube dashboard — url
  • Ssh into minikube
minikube ssh
  • Run kubectl commands against minikube
kubectl config use-context minikube
kubectl config current-context
kubectl get po -n kube-system
kubectl get po — all-namespaces
kubectl get all — all-namespaces
kubectl api-versions | grep rbac
kubectl version
kubectl cluster-info
kubectl api-versions

Test minikube kubernetes deployment

kubectl run hello-minikube — image=k8s.gcr.io/echoserver:1.4 — port=8080 
kubectl expose deployment hello-minikube — type=NodePort
kubectl get services
kubectl get deploy
kubectl get pod
  • Find IP
minikube ip
  • Find mapped port
kubectl describe service hello-minikube
kubectl get svc hello-minikube
curl http://$IP:$PORT
  • Remove testing deployment
kubectl delete services hello-minikube
kubectl delete deployment hello-minikube
eval $(minikube docker-env)
docker info

Minikube add-ons

  • List minikube available addons
minikube addons list
  • Enable ingress for minikube K8s
minikube addons enable ingress
  • Enable Elastic fluentd Kibana
minikube addons enable efk
  • Install Helm cli and initialise tiller
choco install kubernetes-helm
helm init

Post Helm installation configuration

kubectl — namespace=kube-system edit deployment/tiller-deploy
  • Change automountServiceAccountToken to true
automountServiceAccountToken true
  • Or you can do it in one liner
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"automountServiceAccountToken":true}}}}'
  • Check Helm installation
helm version
helm search
kubectl get svc -n kube-system
helm ls — debug
  • Upgrade Helm
helm init --upgrade
  • Helm update repositories
helm repo update
  • Let’s try to deploy some packages and inspect Ex. mysql
helm inspect stable/mysql
helm install stable/mysql

Install helm packages for Prometheus and Grafana

helm install stable/prometheus
helm install stable/grafana

Get Access to Prometheus

  • Get the Prometheus server URL
  • Get POD_NAME for running Prometheus server
kubectl get pods — namespace default -l “app=prometheus,component=server” -o jsonpath=”{.items[0].metadata.name}”
  • Replace $POD_NAME with output from previous command
kubectl — namespace default port-forward $POD_NAME 9090

Get the Alertmanager URL

  • Get POD_NAME for running Prometheus alert manager
kubectl get pods — namespace default -l “app=prometheus,component=alertmanager” -o jsonpath=”{.items[0].metadata.name}”
  • Replace $POD_NAME with output from previous command
kubectl — namespace default port-forward $POD_NAME 9093

Get the PushGateway URL

  • Get POD_NAME for running Prometheus push gateway
kubectl get pods — namespace default -l “app=prometheus,component=pushgateway” -o jsonpath=”{.items[0].metadata.name}”
  • Replace $POD_NAME with output from previous command
kubectl — namespace default port-forward $POD_NAME 9091

Get Access to Grafana

  • Get your ‘admin’ user password in base64 and decode by running:

This works only under Linux :)

kubectl get secret — namespace default interested-moth-grafana -o jsonpath=”{.data.admin-password}” | base64 — decode ; echo
  • Get the Grafana URL
  • Get POD_NAME for running Grafana
kubectl get pods — namespace default -l “app=grafana” -o jsonpath=”{.items[0].metadata.name}”
  • Replace $POD_NAME with output from previous command
kubectl — namespace default port-forward $POD_NAME 3000
  • Deploy k8s dashboard for docker k8s “minikube comes with dashboard deployed”
helm install stable/kubernetes-dashboard
kubectl proxy
  • In web browser use below link to access kubernetes dashboard
http://localhost:8001/ui
  • Or
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

Get Istio installation

git clone https://github.com/istio/istio.git 
cd istio
kubectl create -f install/kubernetes/helm/helm-service-account.yaml
helm init — service-account tiller
helm install install/kubernetes/helm/istio — name istio
helm delete — purge istio

--

--