Kubernetes Local Development With Minikube on Hyper-V Windows 10
Devs typically like to be online when they work, but this tutorial will show you how to develop with Kubernetes offline.
Join the DZone community and get the full member experience.
Join For FreeMost software development is currently done online, especially development that requires Kubernetes and the cloud. In many cases when developers travel and don’t have reliable access to the Internet, it's good to have a local development environment that can be run on a laptop and provide basic Kubernetes setup to continue the development process in a more productive way.
In this article, I show how minikube allows you to run functional Kubernetes as single node cluster on a laptop in Windows 10 using Hyper-V Hypervisor.
Let’s start by installing and configuring minikube with Grafana, Prometheus, Helm, and Istio on Windows 10.
Prerequisites 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," and you will see a 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 PowerShell as Administrator and running Hyper-V Manager
mmc.exe virtmgmt.msc
Or we can use only PowerShell for the rest of the configurations.
Creating External Switch
Using PowerShell (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 an interface connected to the 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 PowerShell as its focus for delivering packages.
Follow the Installation Guide or follow the 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 installed 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
-
vm-driver Hyper-V
: Specifies Hypervisor driver to be used -
cpus 4
: Specifies number of CPU “cores” allocation, if not specified, “Default is 2” -
memory=4096
: Specifies the amount of RAM allocated, if not specified, “Default is 2048” -
hyperv-virtual-switch “VM-External-Switch”
: Specify virtual network switch 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
Check minikube status
minikube status
minikube service list
Launch 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-helmhelm 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 versionhelm 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 using MySQL as an example.
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}”
Note: 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}”
Note: 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:
Note: 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}”
Note: Replace $POD_NAME
with the output from the 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 open in browser
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
Opinions expressed by DZone contributors are their own.
Comments