
Minikube in Hyper-V with nested virtualization
Hi guys, how are you?
I hope you are all doing fine!
Today, I’d like to give you a tutorial on Minikube.

I’ve been struggling with minikube inside a VM, because nested virtualization is not enabled by default.
I know I could have just used VMWare or XEN, but I wanted something simpler, and easier.
So I decided to go with Hyper-V on my physical host. But here’s where things got interesting. Nested virtualization is a bi***.
Setting up the Hypervisor
The first thing to do is to enable Hyper-V on your Windows machine.
In order to do this, open a Powershell as Administrator and run:
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
If you want to try another method, follow this link.
Setting up Vagrant
I’m using Vagrant, because things get a whole lot easier. If you have never used it, please, check out their website.
You can download it here.
After you have done this, select a directory to save a Vagrantfile.
A Vagrantfile is the main file to organize your vagrant machines, you don’t need to worry about images, vdi, snapshots or anything. Just code you machine. Seems cool!
In the selected directory, create a file called Vagrantfile, no extension:
Nice!
Running the VM
Now, just open a CMD as Administrator and run:
vagrant up --provider=hyperv
This will boot up the machine.
To SSH into it, just run:
vagrant ssh wbsv1
Nice! Now you are inside your VM on Hyper-V.
Making a nested virtualization Machine
That’s cool. But we cannot go into our machine and run a hypervisor. It’ll crash. We need to enable it first.
Well, I’ve researched a lot for this. The easier method that I’ve founded was this one:
Go into this link, or grab the following Powershell script:
Now, open a Powershell as Administrator, and run this script.
You may not be able to do this in the first time, because Powershell does not allow you to run “strange” scripts. To bypass this, run:
Set-ExecutionPolicy -ExecutionPolicy Bypass
Now, run the script:
\enable-nested.ps1 [YOUR VM NAME INSIDE HYPERV]
Don’t forget to change your VM name, which is showing on Hyper-V Manager.
Installing a bunch of necessary stuff
This is the boring part, we now have to install a lot of stuff. Some you may need, some of them are just for my confort. Choose whichever you like. I’ll tell you which one is a must.
First, SSH into your machine:
vagrant ssh wbsv1
wbsv1 is my hostname on Vagrantfile.
Now, you are inside the VM.
sudo suyum update -yyum install -y kernel-devel kernel-headers gcc make perl wget vimwget https://www.virtualbox.org/download/oracle_vbox.ascwget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repoyum install -y VirtualBox-6.0/usr/lib/virtualbox/vboxdrv.sh setupsystemctl status vboxdrvsystemctl start vboxdrvsystemctl status vboxdrv
wget and vim are not a must. But I like them. Choose the editor you like. All the others packages are a must, sorry.
The first command is to update your yum repos. After that we need to install a bunch of stuff, if you want to know them a little better, you can check out this and this link.
You may have a problem with kernel version on Virtualbox. To solve this, you must install you kernel-devel version. Run the following to know which exactly version to install:
uname -r
yum install kernel-devel-[CURRENT_KERNEL]
Now, you might see something like this:
● vboxdrv.service - VirtualBox Linux kernel moduleLoaded: loaded (/usr/lib/virtualbox/vboxdrv.sh; enabled; vendor preset: disabled)Active: active (exited) since Wed 2019-04-03 16:18:58 UTC; 10min agoProcess: 63501 ExecStart=/usr/lib/virtualbox/vboxdrv.sh start (code=exited, status=0/SUCCESS)Apr 03 16:18:58 wbsv1 systemd[1]: Starting VirtualBox Linux kernel module...Apr 03 16:18:58 wbsv1 vboxdrv.sh[63501]: vboxdrv.sh: Starting VirtualBox services.Apr 03 16:18:58 wbsv1 systemd[1]: Started VirtualBox Linux kernel module.
Nice. Everything worked as planned.
Now, we need to setup our K8s environment.
Installing Docker
Docker is always useful. To install it:
This will download the latest CE version and enable it on reboot.
Installing Kubectl
Now, install the K8s cli:
This will add the kubernetes repo to your machine, and download it from yum.
Installing Minikube
Now, for the last part:
This will download the latest version of Minikube, today it’s on v1.0.
And it will add it to your path. Remember that the path on Centos is on /usr/bin/.
Now, just run your minikube cluster:
minikube start
It may take a while to download the images and get everything up and running. But it sure works.
If you had any doubts, contact me on my Linkedin.
This tutorial is also on my Gitlab, under the basics/Setup.md file.
Ok, till next time, guys. See ya!