Simplified Kubernetes Workflow: Launching Minikube on Hyper-V Compatible Windows 10 Machines
Ava Parker
Posted on September 10, 2024
In today's software development landscape, online collaboration is the norm, especially when working with Kubernetes and cloud-based technologies. However, when developers find themselves without a reliable internet connection, having a local development environment that can run on a laptop and provide a basic Kubernetes setup is crucial for maintaining productivity.
In this article, I will demonstrate how minikube enables the deployment of functional Kubernetes as a single-node cluster on a laptop running Windows 10, utilizing the Hyper-V Hypervisor.
Let’s begin by installing and configuring minikube with Grafana, Prometheus, Helm, and Istio on Windows 10.
Development Machine Environment Prerequisites
- VT-x/AMD-v virtualization must be enabled in the BIOS (requires a machine restart)
- Enable Hyper-V: Navigate to “Windows features On or Off” and locate the Hyper-V section. Enable it, and then restart your machine.
Hyper-V Installation
Hyper-V has been 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 the Control Panel at “Turn Windows features On or Off” under “Programs and Features.” Activate the “Hyper-V” checkbox, apply the change, and follow the on-screen instructions.
Network Configuration
First, you need to configure a new virtual switch to enable your virtual machine to connect to the internet. Once Hyper-V is enabled, launch the Hyper-V Manager.
Configuration can be done via the GUI by opening PowerShell as Administrator and running Hyper-V Manager
mmc.exe virtmgmt.msc
Alternatively, we can utilize PowerShell exclusively for the remaining configurations.
Establishing an External Switch
Using PowerShell (run as Administrator)
- Retrieve a list of the network adapters in the host. Typically, you should see “Ethernet” and “Wi-Fi” on a laptop.
Get-NetAdapter
- Create the external switch, naming it VM-External-Switch, and bind it to the network adapter named Wi-Fi retrieved from the previous command. You may need to modify the -NetAdapterName to an interface connected to the internet.
New-VMSwitch -name ExternalSwitch -NetAdapterName "Ethernet 3" -AllowManagementOS $true
The most straightforward way to install minikube is to deploy it via choco.
Chocolatey is a Windows package manager, similar to apt-get or yum, designed to facilitate rapid installation of applications and tools. Built on the NuGet infrastructure, it utilizes PowerShell as its primary focus for delivering packages.
Follow the Installation Guide or execute 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 available upgrades for Chocolatey:
choco upgrade chocolatey
Install the kubectl CLI:
choco install kubernetes-cli
Set up minikube:
Using PowerShell (run as Administrator):
choco install minikube
Verify minikube installation:
minikube version
Explore available Kubernetes versions:
minikube get-k8s-versions
Update minikube:
minikube update-check
Initialize minikube
Review available initialization options:
minikube.exe start — help
-
vm-driver Hyper-V
: Specifies the Hypervisor driver to utilize -
cpus 4
: Allocates the number of CPU “cores”, defaulting to 2 if unspecified -
memory=4096
: Allocates the amount of RAM, defaulting to 2048 if unspecified -
hyperv-virtual-switch “VM-External-Switch”
: Specifies the virtual network switch to utilize, “VM-External-Switch” created in previous steps -
kubernetes-version string
: Specifies the version of Kubernetes to install (e.g., v1.2.3)
Post-minikube Installation
-
Halt minikube k8s VM
minikube stop
Disable Dynamic RAM allocation in Hyper-V
Set-VMMemory minikube -DynamicMemoryEnabled $false
Restart minikube k8s VM
minikube start
Deploy additional Kubernetes components
List minikube addons
minikube addons list
Enable Heapster for cluster performance monitoring
minikube addons enable heapster
Post-installation checks for minikube
Check minikube status
minikube status
minikube service list
Launch Kubernetes dashboard
minikube dashboard
Verify dashboard URL
minikube dashboard — url
Establish a secure shell connection to minikube
minikube ssh
Execute 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
Determine IP address
minikube ip
Find mapped port number
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
Enumerate minikube available add-ons
minikube addons list
Activate Ingress for minikube K8s
minikube addons enable ingress
Activate 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
Modify automountServiceAccountToken
to true
automountServiceAccountToken true
Alternatively, you can do it in one command
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"automountServiceAccountToken":true}}}}'
Verify Helm Installation
helm version
helm search
kubectl get svc -n kube-system
helm ls — debug
Upgrade Helm
helm init --upgrade
Update Helm Repositories
helm repo update
Let’s attempt 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
Access Prometheus.
-
Obtain the Prometheus Server URL
-
Get the
POD_NAME
for the running Prometheus server
kubectl get pods — namespace default -l “app=prometheus,component=server” -o jsonpath=”{.items[0].metadata.name}”
Note: Replace $POD_NAME
with the output from the previous command
kubectl — namespace default port-forward $POD_NAME 9090
Obtain the Alertmanager URL
Get the POD_NAME
for the 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 the output from the previous command
kubectl — namespace default port-forward $POD_NAME 9093
Obtain the PushGateway URL
Get the POD_NAME
for the running Prometheus push gateway
kubectl get pods — namespace default -l “app=prometheus,component=pushgateway” -o jsonpath=”{.items[0].metadata.name}”
Replace $POD_NAME
with the output from the previous command
kubectl — namespace default port-forward $POD_NAME 9091
Gain Access to Grafana
Retrieve your ‘admin’ user password in base64 and decode it by executing:
Note: This method is exclusive to Linux environments.
kubectl get secret — namespace default interested-moth-grafana -o jsonpath=”{.data.admin-password}” | base64 — decode ; echo
-
Obtain the Grafana URL
-
Retrieve the
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 the Kubernetes dashboard for Docker Kubernetes (note: Minikube comes with the dashboard pre-deployed)
helm install stable/kubernetes-dashboard
kubectl proxy
In your web browser, access the Kubernetes dashboard using the following link:
http://localhost:8001/ui
Alternatively, open in your browser:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
Install Istio.
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
Posted on September 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
September 10, 2024
September 20, 2024