Why minikube needs an explicit hypervisor - docker

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.

Related

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.

Kubernetes in Docker for Windows

I have not installed minikube in my local windows machine.I have only used kubernetes in docker. Docker settings checked enable Kubernetes.Everthing is ok. I created a Pod and a Service succesfully.Finally I need to an ip different from localhost for accessing through browser.
http://I_need_an_ip:31515
What is equaliant minikube ip when use kubernetes in docker for windows, without minukube?
"kubectl describe node docker-for-desktop" gives you the internal IP address that the docker for desktop node is running on (see also Minikube vs Kubernetes in Docker for Windows )

Can't connect to VM from Host in HostOnlyNetwork Configuration

I am trying to create a VM on my Ubuntu linux machine. The VM I am trying to create is 12.04 Ubuntu 32 bit virtual machine. I have had success creating said VM from a Windows environment, but when I migrated to a 16.04 Ubuntu environment I can't replicate my success. The problem comes from when I chose a HostOnly network for my VM. On my windows computer, after setting the IP and subnet mask using Host network manager on Virtualbox, Upon selection of a VirtualBox host only adapter, I was able to make Packer ssh into my VM. However, when I tried the same thing on my Ubuntu machine, going to preferences -> network, and setting the IP and subnet mask, whenever I select VBoxnet0 and than have Packer attempt to ssh or when I ping into my VM from my Ubuntu machine, I get host unreachable. Both netstat and ifconfig are telling that vboxnet0 is there. Based on what I have written, what might be the reasons I can't connect to my VM?

Why minikube needs a VM

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.

If docker uses virtual machine to run on a mac then what is its advantage over vagrant?

So I have read this in many places that docker is faster and more efficient because it uses containers over VMs but when I downloaded docker on my mac I realized that it uses virtual box to run the containers. I believe on a linux machine docker doesn't need virtual box and can run on Linux Kernel. Is this correct ?
Back to original question. Is docker still faster/efficient because it uses a single VM to run multiple containers as opposed to Vargrant's new VM for every environment ?
I believe on a linux machine docker doesn't need virtual box and can run on Linux Kernel. Is this correct ?
Yes, hence the need for a VirtualBox Linux VM (using a TinyCore distribution)
Is docker still faster/efficient because it uses a single VM to run multiple containers as opposed to Vargrant's new VM for every environment ?
Yes, because of the lack of Hypervisor simulating the hardware and OS: here you can launch multiple containers all using directly the kernel (through direct system calls), without having to simulate an OS.
(Note: May 2018, gVisor is another option: a container, simulating an OS!)
See more at "How is Docker different from a normal virtual machine?".
Of course, remember that Vagrant can use a docker provider.
That means you don't have to always provision a full-fledged VM with Vagrant, but rather images and containers.
Vagrant.configure("2") do |config|
config.vm.provider "docker" do |d|
d.image = "foo/bar"
end
end
See Vagrant docker provisioner.

Resources