Kubernetes in Docker for Windows - docker

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 )

Related

Access to a kubernetes cluster from inside a docker container

I have some docker containers running with docker compose (node.js, databases, nginx...). I have also a minikube Kubernetes cluster.
I am trying to communicate from node.js container to Kubernetes to manage some nodes (using Kubernetes API and the config file generated). But I can't get access to the Kubernetes, I tried to ping minikube IP from a docker container but I get not connection. But from my local machine, works without problems.
Someone can help? What is wrong?
My machine is a Linux Ubuntu 20.04 and minikube uses docker driver.
For Kubernetes to work, you need to have two network interfaces configured. One in a private network and another in dhcp that allows you to get an internet connection. You must take into account that the dhcp address will coincide with the ip used at the time of initializing the cluster, so you must assign a static ip.
Check your etcd.yaml file
maybe this network file configuration can help you
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
addresses: [10.0.0.1/24]
dhcp4: no
dhcp6: no
enp0s8:
addresses: [192.168.XX.XX/24]
dhcp4: true
dhcp6: no

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.

How to access `docker-compose` containers, in Minikube

Issue:
I want my web-server to have either a Kubernetes config and a Docker-Compose config.
I run them on a MacBook (no native containers support), so at the moment I
run docker-compose on Docker Desktop
run kubectl on a Minikube VM
(I stick to Minikube because of the convenient commands like minikube ip & minikube service, that I rely on in my scripts)
This makes slow and inconvenient to switch from one setup to the other (suspend Minikube, start Docker Desktop, rebuild the images, re-run the services; and vice-versa).
They won't share built images or containers, and they run in different environments.
Attempt
I tried running docker-compose on Docker from the Minikube VM.
Works fine, but I cannot connect to the service, because there is no tunnelling or port-forwarding from the Host machine to the Minikube machine
(while compose takes care of the inner forwarding from $(minikube ip):8081 to docker-container-webserver:8080.
Question
How to open the connection from the Host machine (browser) to the container (web-server) running inside Minikube?
I tried minikube tunnel but it didn't seem to help (it is designed to work with Kubernetes LoadBalancer services).

Skaffold dev with remote docker context

I am working on a web application with all the infrastructure based on Kubernetes. In my local environment, I am using Skaffold.
I have two computers (Desktop and Laptop) with 8Gb of RAM each. By starting minikube (virtualbox driver) and skaffold dev the Deskop is freezing.
So I decided to use the Laptop for coding and the Desktop for running minikube and everything related.
I successfully managed to set up kubeconfig on the laptop to have a context with the minikube server.
Actually, The issue is skaffold.
When I run skaffold dev, it fails because minikube of the Deskop doesn't see the images build by skaffold on my laptop. kubectl get po returns ImagePullBackOff.
That is because skaffold uses the local docker to build the image.
The question is how to make skaffold use the docker install in my Desktop?
I changed the docker context of my laptop so that it's linked to the Desktop context but it's still not working, skaffold is still using the default docker context installed in my laptop.
How to make the images build by Skaffold being available on my Desktop?
Is it possible for Skaffold to use a remote docker context? If yes, how?
Minikube uses its own Docker installation to power its cluster. This daemon runs in Minikube's VM (or container, if using the docker driver) and is completely independent from the host's Docker daemon (your Desktop). You can access to Minikube's daemon by setting the environment returned by minikube docker-env.

Access host resources from a kubernetes cluster service when minikube started with DOCKER vm driver

I have been able to successfully provision services inside a kubernetes minikube cluster to connect to services such as cassandra, kafka, etc installed on the host machine so far when I started the minikube cluster with the virutalbox vm.
minikube start --driver=virtualbox
For this I had to defined k8s manifest say fror cassandra endpoint with an IP address of the host machine identified from within the minikube cluster via following command as suggested here:
minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"
But when I start the minikube cluster with docker as VM driver, I am not able to figure out the ip address of the host machine as identified from inside the cluster because the command to fetch the same doesn't work.
minikube start --driver=docker
minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"
bash: route: command not found
Please suggest how could this ip address be retrived?
I think you overcomplicate things when it is not needed.
Since you want to run a testing environment (minikube suggests that) you should always want to start minikube with:
minikube start --driver=docker
Now the IP address of the Kubernetes cluster can be found simply by typing:
minikube ip
Or:
kubectl cluster-info | grep master
This command will show you the ip address that Kubernetes is running from, and the port (usually 6443).
Unfortunately it is not possible to it that way while using Docker as a driver due to the limitations of Docker VM.
There is a workaround listed here, saying:
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network
access). From 18.03 onwards our recommendation is to connect to the
special DNS name host.docker.internal, which resolves to the internal
IP address used by the host. This is for development purpose and will
not work in a production environment outside of Docker Desktop for
Mac.
The gateway is also reachable as gateway.docker.internal.
But there is no official analogical way to do so with Minikube.
I know that it might not be the exact thing you wanted but I see three options as a workaround:
Use a different driver.
Try using Telepresence as a proxy.
Try Routing an internal Kubernetes IP address to the host system.
I hope it helps.

Resources