Summary
How to run minikube in a Virtual Machine Ubuntu vm_VT-X/AMD-v
As a developer, I like to have a reproducable environment. My customers often provide the technical specifications of their environment and I like to reproduce them locally so I can be the closest to their environment.
To be able to install minikube on a virtual machine, running virtualbox, you need to use the correct driver (none).
In this tutorial, I will show you how to install and setup minikube on the virtual machine. The operating system will be Ubuntu.
TL;DR
To install minikube on a virtual machine, running virtualbox, follow these steps:
-
Install minikube as you would normally do. Check my tutorial here
- Configure minikube not to use any driver. The none driver does not require any nested virtualization.
- Install docker-ce following the instructions of your operating system. (Mine is ubuntu)
- Enable docker and start it
- Start minikube
The problem I was facing
I was tring to install minikube in a virtualbox VM running Ubuntu OS. I have enabled VT-X/AMD-v for the vm.
But i’m getting following error when I try to start my minikube.
# minikube start
You get this output :
Starting local Kubernetes cluster...
E0217 15:00:35.395801 3869 start.go:107] Error starting host: Error creating host: Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory".
Retrying.
E0217 15:00:35.396019 3869 start.go:113] Error starting host: Error creating host: Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory"
================================================================================
An error has occurred. Would you like to opt in to sending anonymized crash
information to minikube to help prevent future errors?
To opt out of these messages, run the command:
minikube config set WantReportErrorPrompt false
================================================================================
Please enter your response [Y/n]:
What is happening?
VirtualBox does not support VT-X/AMD-v in nested virtualisation. You can read more here [^2]
So there are few approaches to solve this:
- Run minilube on my machine directly, no virtualbox VM.
- Use a different hypervisor that does support VT-X/AMD-v in nested virtualisation (like Xen, KVM or VMware).
- Run Minikube directly using Docker and the “none” driver option
The solutions
There are few solutions I could implement.
Install minikube on my machine directly
There are compiled binaries for Windows, MacOs and Linux so I could have just installed minikube on my host directly.
Pros
- Easy to install
Cons
- Liked to my computer
- Need to reinstall and setup if I change my computer or need to reinstall the OS.
- I can’t have a comparable test environment before deploying my solution to the customer’s environment.
Run minikube with driver none
The kubernetes documentation says :
Minikube also supports a –vm-driver=none option that runs the Kubernetes components on the host and not in a VM. Using this driver requires Docker and a linux environment, but not a hypervisor [^1].
- Install docker on the VirtualBox VM
- Configure minikube to use the
none
driver.
minikube config set vm-driver none
- Enable docker on the VM machine
systemctl enable docker
You will get this output.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
systemctl start docker
- Start minikube
minikube start
You will get this output.
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.10.0
Downloading kubelet v1.10.0
Finished Downloading kubelet v1.10.0
Finished Downloading kubeadm v1.10.0
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks
When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions. An example of this is below:
sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration
sudo chown -R $USER $HOME/.kube
sudo chgrp -R $USER $HOME/.kube
sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration
sudo chown -R $USER $HOME/.minikube
sudo chgrp -R $USER $HOME/.minikube
This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
Loading cached images from config file.
Use another hypervisor
VirtualBox is an hypervisor that you install on your machine to host the virtual machines. Since it does not support VT-X/AMD-v in nested virtualisation, you can use the alternatives :
- Xen
- KVM
- VMware
- etc.
Conclusion
You can install minikube inside a VM. But to make it run, you need to make some adjustments. But it is possible to make it happen.
Running it inside a VM allows you to automate your development worklow. You ca even think of tools like vagrant to provision your VM automatically to that you have a reproducable environment.
References
[^1]https://stackoverflow.com/a/52635546/5730444
[^2]https://www.virtualbox.org/ticket/4032