Why minikube needs a VM - docker

I guess that minikube needs VirtualBox because of dockers' dependencies, but my current docker version doesn't need it.
So do I still need VirtualBox or another VM to start minikube?

this is only case on window or osx, do need virtualbox, vmware to create minikube vm using boot2docker, in Linux even Linux VM minikube can directly run kubernetes in host docker when choice --vm-driver none, which uses localkube.

Minikube uses the docker machine to manage the kubernetes VM, so it abstracts the plugin architecture that Docker Machine uses to provide a consistent way to manage various VM providers. Minikube embeds VirtualBox and VMware Fusion drivers so there are no additional steps to use them. However, other drivers require an extra binary to be present in the host PATH like KVM, xhyve, HyperV, etc.
Yes you need the virtualbox along with respective driver to run the kubernetes cluster on your machine and it is because of docker dependencies. Minikube started a virtual machine for us(based on our local environment), and a Kubernetes cluster is running in that VM i.e. all your nodes and services are running under the VM box.

You can work on Minikube even without installing VirtualBox.
Minikube also supports a --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.
If you’re using the none driver in Debian or a derivative, use the .deb packages for Docker rather than the snap package, which does not work with Minikube. You can download .deb packages from Docker.
You can also use --driver=docker
For more information, you can refer here

Minikube creates a simple local kubernetes cluster having one VM. Minikube needs a hypervisor such as VirtualBox or KVM... to create this VM.
Minikube won't be able to start if VirtualBox (which is the default) is not available.
minikube start
You will get this error:
VBoxManage not found. Make sure VirtualBox is installed and VBoxManage
is in the path

As per minikube Windows Getting started you can now choose between Virtual Box and Hyper-V for Windows, meaning Virtual Box is not mandatory if you have Hyper-V.
Prerequisites
Windows 8 or above
A hypervisor, such as Hyper-V or VirtualBox
Hardware virtualization support must be enabled in BIOS
4GB of RAM

Using minikube start --driver=docker works just fine. The docker engine could act as a virtual machine.

Related

Why minikube needs an explicit hypervisor

While running Minikube on mac, we need to specify vm-driver as it needs a hypervisor to run the virtual machine on which it would run the K8 Cluster.
Why can’t Minikube use the hypervisor of the host machine say mac as host machine already has a hypervisor by default ?
Minikube has several drivers that can plug into different virtualization backends. That includes the ability to run the cluster inside a single container (the current default) or to use the Hyperkit hypervisor (which Docker Desktop also uses).
If you want to use a different hypervisor by default, you can configure minikube to do that:
minikube config set driver hyperkit
Minikube creates a simple local kubernetes cluster having one Virtual Machine. Minikube needs a hypervisor such as VirtualBox or KVM to create this VM. Minikube started a virtual machine for us(based on our local environment), and a Kubernetes cluster is running in that VM i.e. all your nodes and services are running under the VM box! This is only case on windows or osx.
You can work on Minikube even without installing VirtualBox. Minikube also supports a --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.

Unable to connect to running docker containers (minikube docker daemon)

When I run my docker container using Docker Desktop for Windows I am able to connect to it using
docker run -p 5051:5000 my_app
http://0.0.0.0:5051
However when I open another terminal and do this
minikube docker-env | Invoke-Expression
and build and run the same container using the same run command as above
I cannot connect to the running instance.
Should I be running and testing the containers using Docker Desktop, then using minikube to store the images only (for Kubernetes)? Or can you run them and test them as well through minikube?
That's because on your second attempt, the container is not running on the host but on the minikube VM. You'll be able to access it using the minikube VM IP.
To get the minikube ip you can run minikube ip
Why ?
Invoking minikube docker-env sets all the docker env variable on your host to match the minikube environment. This means that when you run a container after that, it is run with the docker daemon on the minikube VM.
I asked you if there are any specific reasons to use Docker Desktop and Minikube together on a single machine as these are two competitive solutions which basically enable you to perform similar tasks and achieve same goals.
This article nicely explains differences between these two tools.
Docker-for-windows uses Type-1 hypervisor, such as Hyper-V, which are
better compared to Type-2 hypervisors, such as VirtualBox, while
Minikube supports both hypervisors. Unfortunately, there are a couple
of limitations in which technology you are using, since you cannot
have Type-1 or Type-2 hypervisors running at the same time on your
machine
If you use Docker Desktop and Minikube at the same time I assume you're using Type-1 hypervisor, such as mentioned Hyper-V, but keep in mind that even if they use the same hypervisor, both tools create their own instances of virtual machine. Basically you are not supposed to use those two tools together expecting that they will work as a kind of hybrid that lets you manage single container environment.
First check what hypervisor you are using exactly. If you're using Hyper-V, simple Get-VM command in Powershell (more details in this article) should tell you what you currently have.
#mario no, I didn't know minikube had a docker daemon until recently
which is why I have both
Yes, Minikube has built in docker environment (in fact it sets everything up, but yes, it also sets up container runtime) so basically you don't need to install docker additionally, and as #Marc ABOUCHACRA already suggested in his answer, Minikube runs the whole environment (single node k8s cluster with docker runtime) on a separate VM. Linux version has an option --vm-driver=none which allows you to use your host container runtime and set-up k8s components on it, but this is not the case with Windows version - here you can only use one of two currently supported hypervisors: Hyper-V or VirtualBox (ref).
I wouldn't say that Docker Destkop runs everything on your host. It also uses Type-1 hypervisor to run the container runtime environment. Please check the Get-VM command on your computer and it should be clear what VMs you have and created by which tool.

Is it possible to run Minikube with VirtualBox on windows 10 along with Docker?

I want to use minikube on Windows 10. I have installed VirtualBox and want to use it as the virtual machine for minikube. Also I installed Docker for windows. But during installation Docker forced to use Hyper-V as default. But that means I can no longer use VirtualBox to run minikube! Not sure what am I missing here.
I have used minikube on Mac and there it was much simpler: simply open VirtualBox and then run command on command line: minikube start . However in Windows 10 it seems much more complicated.
Just to make things clear: Docker requires Hyper-V to be turned on, and Virtualbox requires Hyper-V to be turned off. The reason is they use different virtualization technologies, to be exact - type 1 and type 2 hypervisors:
Type 1 hypervisor: hypervisors run directly on the system hardware – A
“bare metal” embedded hypervisor, Type 2 hypervisor: hypervisors run
on a host operating system that provides virtualization services, such
as I/O device support and memory management.
I've found that there are few approaches to this issue. One of them is adding another boot option and rebooting every time you needed to switch between hypervisors, but it seems that this method is as good as manually turning off Hyper-V, restarting and then using your minikube in VirtualBox. This is probably not the desired state.
So as you can't use them at once, you will have to use a tool that was introduced by Docker for older Windows systems. This is because Docker Toolbox is not using Hyper-V.
Please treat this solution as a workaround, and even Docker does not recommend using Docker toolbox if you can use Docker. Also, you could achieve the same results with minikube running on Hyper-V.
0) Uninstall Docker, turn off Hyper-V, delete all traces of minikube, uninstall VirtualBox (if you tried to run it previously.)
1) Install [Docker Toolbox] - choose full installation2
2) Install Virtualbox, run docker run hello-world inside of Docker Quickstart Terminal and verify if everything is working correctly.
3) Install minikube for Windows (I used chocolatey)
4) Run minikube start.
I've tested this steps, and I was able to run Docker containers in the Docker toolbox in the meantime initializing a Kubernetes cluster in minikube.

Does "Docker On Windows" launch a linux virtual machine?

I'm aware that the old Docker Toolbox uses VirtualBox to run a minimal linux virtual machine for Docker using boot2docker which is a minimal light-weight Linux OS. Now, with the new Docker on Windows they claim that they use HyperVisor on Windows 10 Pro directly.
Does this mean the Docker on Windows package got rid of the Linux virtual machine totally, or is there still a Linux virtual machine being used on Windows?
A container is considered “native”, if it can run directly on the host operating system.
Linux Container - A Linux application that runs in an isolated Linux environment.
This same container can be run on a Windows OS using virtualization to emulate a Linux environment, but the container is still running on Linux.
Windows (Server) Container - A Windows application that runs in an isolated Windows environment.
Docker on Windows to run a Linux container requires virtualization. The available options are:
VirtualBox (Docker Toolbox)
Hyper-V backend (Docker Desktop)
WSL2 backend (Docker Desktop)
The Container (and Docker) terminology is very confusing, especially with Windows nuances. See Docker Container in Linux and Windows for an overview with many useful reference links.

Can I run Docker in a Virtual Machine?

I tried to run Docker on a virtual machine.
Host : MacBook
VM : Parallels Windows 7
And error occurs:
Is it possible?
If the VM is a Linux, you can do this without any problem - on Linux, the Docker is essentially a well-worked chroot. Thus, the Linux docker is not virtualization.
In the case of Windows, it is not so easy. Windows Docker internally uses Hyper-V to emulate the containers. Which means that you can only run, if you can use nested virtualization:
On your host machine runs a Windows VM
Inside your Windows VM, runs a HyperV
HyperV is managed by the docker installed on your virtual Windows.
I tried qemu/kvm, virtualbox and vmware player. I configured them deeply and strongly, I've hacked them, I did every possible to do. Only the last worked (VMWare).
There are significant speed costs, but it may be useful for development on Linux, and then trial-test on Windows configurations.
You will need a lot of ram. At least 16G. 32G is better. A relative useful configuration would be:
32GB physical RAM for the physical host
12GB virtual RAM for the Windows VM running on it
8GB virtual RAM inside the Windows VM for the HyperV Linux host.
Sometimes it will be a little bit buggy, but only your HyperV will crash out, your virtual Win, or your host machine won't. It is okay for testing a docker container on a Windows machine, what you've developed on a Linux. Don't create mission critical servers on this way. :-)
You're using Docker Machine in your Windows VM, which is actually going to create a Linux VM inside the Windows VM on your Mac. You can do that, but you need to enable nested virtualization - which I'm not sure you can do in Parallels 7.
Instead you can run Docker Machine on the Mac directly and use Parallels to create the Linux VM - which means Docker is running in a Linux VM on your Mac, and you don't need nested virtualization.
Or preferably use Docker for Mac if your OS supports it, it's the latest product and has much better host integration than Docker Machine.
If you would be using Windows 10/11 Pro or Enterprise and Hyper-V, then all you must do is to enable nested virtualization. On your host, just run (with your guest off):
> Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
Now you can start your guest and run Docker Desktop as normal.
According to Docker's terms I don't think it's allowed. Section 4.1(b)(vii) says you shall not "use the Service on virtual machines." For clarification, "'Service' refers to the applications, software (including any Open Source Software), products and services provided by Docker, including any beta or trial versions."
If I am reading this right, that means it's illegal to run Docker on any VM.
Worked perfectly fine. Base OS win 10 pro with VirtualBox Version: 6.1 and vagrant with ubuntu 20.04. Using vagrant box follow docker instructions. With vagrant public network no need for port forwarding all apps were accessible.
Previous persons comment is very concerning considering on Windows and Mac you run docker inside a virtual machine lul. Windows uses WSL2 and Mac uses an arm linux machine to manage its docker.
Also, you can run docker in a vm, but it must be linuxOS vm as windows 7 does not support docker.

Resources