9

I have created one service called fleetman-webapp:

apiVersion: v1
kind: Service
metadata:
 name: fleetman-webapp

spec:
 selector:
  app: webapp

 ports:
  - name: http
    port: 80
    nodePort: 30080

 type: NodePort

also, a pod named webapp:

apiVersion: v1
kind: Pod
metadata:
 name: webapp
 labels:
  app: webapp
spec:
 containers:
 - name: webapp
   image: richardchesterwood/k8s-fleetman-webapp-angular:release0

I have checked the minikube ip:

192.168.99.102

But when I type in the browser 192.168.99.102:30080, the webapp is not reachable:enter image description here

Please note that I use Ubuntu latest version. I have verified furthermore if proxies and firewalls are active:

cat /etc/environment:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

iptables -L:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (1 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere 

I have also disabled ufw in Ubuntu, but no success, the url 192.168.99.102:30080 .

Would you help me please ? thanks in advance for your answer.

Mohamed Aoutir
  • 613
  • 3
  • 11
  • 22
  • As far as I can see you are missing some of the `iptables` rules. Were you following any particular guide for installing minikube? I recreated your `deployment` and `service` with `sudo minikube start --vm-driver=none` and it works. – Dawid Kruk Mar 17 '20 at 07:19
  • @DawidKruk, yeah it works when I changed the driver from VirtualBox to none. Could you explain to me why?. Thank you anyway – Mohamed Aoutir Mar 17 '20 at 13:57
  • 1
    As you did not specify which `Hypervisor` is used, I assumed Docker as hypervisor with `--vm-driver=none` (reason: iptables). Now I can see it's Virtualbox. Give me some time, I will post an answer with more explanation. – Dawid Kruk Mar 17 '20 at 14:49
  • @DawidKruk thanks for your time, note that I run minikube in VM Ubuntu, previously minikube is started in virtualbox; It's like a nested VM. – Mohamed Aoutir Mar 17 '20 at 16:53
  • If you are having a virtual machine with Ubuntu and you are running another virtual machine with minikube and `--vm-driver=virtualbox` inside of it you will need some additional configuration to be able to access kubernetes resources from main host. You should be okay when using `--vm-driver=none` on the Ubuntu virtual machine. More explanation you can find in my answer. – Dawid Kruk Mar 17 '20 at 17:02

5 Answers5

34

Even though, you are exposing port 30080 via NodePort in minikube, minikube will still not expose it because it will use its own external port to listen to this service. Minikube tunnels the service to expose to the outer world. To find out that exposed port:

minikube service $SERVICE_NAME

so, in your case

minikube service fleetman-webapp
Imam Bux
  • 1,006
  • 11
  • 27
  • It worked just like a magic, but I want to learn behind the scene mechanism, can you please provide link to that resource, explaining this requirement of command. PS ~ I have been learning K8S following a tutorial, where the running pod was accessed without the use of above command, which you provided. – Saroj Feb 05 '22 at 18:57
7

There are a lot of different hypervisors which can work with minikube. Choosing one will be highly dependent on variables like operating system. Some of them are:

  • Virtualbox
  • Hyper-V
  • VMware Fusion
  • KVM2
  • Hyperkit
  • "Docker (--vm-driver=none)" (see the quotes)

There is official documentation talking about it: Kubernetes.io: Minikube: Specifying the vm driver

Choosing Hypervisor will affect how the minikube will behave.

Focusing on:

  • Docker: --vm-driver=none
  • Virtualbox: --vm-driver=virtualbox

Docker

Official documentation sums it up:

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.

-- Kubernetes.io: Install minikube: Install a hypervisor

The output of command$ sudo minikube ip will show IP address of a host machine.

Service object type of NodePort will be available with IP_ADDRESS_OF_HOST:NODEPORT_PORT.

Following with command: $ kubectl get nodes -o wide:

NAME STATUS ROLES  AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
K8S  Ready  master 95s v1.17.3 192.168.0.114 <none>  Ubuntu 18.04.4 LTS 5.3.0-28-generic docker://19.3.8

Please take a specific look on:

INTERNAL-IP
192.168.0.114

It's the same IP address as a host it's working on. You can (for example) curl pods without any restrictions. Please consider reading the article in included citing:

Caution: The none VM driver can result in security and data loss issues. Before using --vm-driver=none, consult this documentation for more information.

You can check what was exposed with command: $ sudo netstat -tulpn

Virtualbox

Creating a minikube instance with --vm-driver=virtualbox will create a virtual machine with Virtualbox as host.

Virtual machine created with this kind of --vm-driver will have 2 network interfaces provided below:

  • NAT
  • Host-only adapter

What is important is that your minikube instance will be accessible by Host-only adapter.

Host-only networking. This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface, similar to a loopback interface, is created on the host, providing connectivity among virtual machines and the host.

-- Virtualbox.org: Virtual networking

For example:

  • minikube host-only adapter will have an address: 192.168.99.103
  • Your host-only adapter will have an address: 192.168.99.1

They must be different!

If you are having issues with connecting to this adapter please check:

  • If minikube's host-only adapter address is responding to ping when minikube start completed successfully.
  • Your host-only adapter is present in your network configuration by issuing either:
    • ip a
    • ifconfig
  • Your host-only adapter address is in range of your minikube instance (subnet)

From my experience reboot/recreation of this adapter worked all the time if something wasn't right.

The output of command$ sudo minikube ip will show IP address of a Host-only adapter.

Following with command: $ kubectl get nodes -o wide:

NAME   STATUS   ROLES    AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE              KERNEL-VERSION   CONTAINER-RUNTIME
m01    Ready    master   29m   v1.17.3   192.168.99.103   <none>        Buildroot 2019.02.9   4.19.94          docker://19.3.6

Please take a specific look once more on INTERNAL-IP and ip address associated with it.

Service object type of NodePort will be available with: IP_ADDRESS_OF_HOST_ONLY_ADAPTER:NODEPORT_PORT.

I recreated your Deployment and Service attached to it and it worked in both --vm-driver=none and --vm-driver=virtualbox cases.

Please let me know if you have any questions in this topic.

Dawid Kruk
  • 8,982
  • 2
  • 22
  • 45
  • 1
    The problem is: despite I have typed IP_ADDRESS_OF_HOST_ONLY_ADAPTER: NODEPORT_PORT in the browser the minikube IP is not reachable. Could you confirm me that IP_ADDRESS_OF_HOST_ONLY_ADAPTER is obtained with the command: sudo minikube ip, because that's what I have done before. – Mohamed Aoutir Mar 18 '20 at 10:25
  • As I said, it will depend on the configuration of your network environment. Host-only adapter will be reachable by the host that spawned the minikube environment. If you are trying to access it from other host it will need additional configuration. If you created your minikube with `--vm-driver=virtualbox` the `minikube ip` will be the address of host-only adapter of minikube's vm. – Dawid Kruk Mar 18 '20 at 10:30
3

For this specific (and really great) course about Kubernetes on Udemy from Richard Chesterwood the following solution should work out of the box on Windows: just start the minikube with hyper-v driver, then it will automatically map all the ports you are expecting onto your host machine, like detailed explained here by Dawid Kruk. Therefore all you need to start minikube "correctly" is the following command:

minikube start --driver=hyperv

Be careful by specifying exact amount of memory you give to this minikube instance. In my experiences hyper-v is a bit sensitive about how much memory you will give to it, what could result in errors:

minikube start --driver=hyperv --memory=8192
...
Not enough memory in the system to start the virtual machine minikube.
Could not initialize memory: Not enough memory resources are available to complete this operation. (0x8007000E).
'minikube' failed to start. (Virtual machine ID D4BC7B61-4E4D-4079-94DE-...)
Not enough memory in the system to start the virtual machine minikube with ram size 8192 megabytes. (Virtual machine ID ...)

Therefore just use the unspecific command given above and hyper-v will figure out, how much memory it really needs on it's own.

ilja
  • 351
  • 2
  • 14
3

I have had the same issue and have been trying to solve that for the last 2 days I have tried to install ingress addon:

minikube addons enable ingress

and also tried to run :

minikube tunnel

looked for a way to allow the host machine to access the container IP address but apparently couldn't find a way to do that.

If you run minikube on docker:

minikube start --driver=docker

you won't be able to access the minikube IP from your host machine since the minikube container's IP address would by accessible through DockerDesktopVM but not from your host machine.

You could run minikube on another driver such as VirtualBox or Hyperv, and that might help.

minikube start --driver=hyperv
minikube start --driver=virtualbox

Read more about the minikube drivers

In fact, that's really annoying if you don't have enough resources on your computer to run both the Docker desktop VM and the minikube VM at the same time and will eventually slow down your computer.

To solve that docker-desktop UI for Mac and Windows provides an easier alternative compared to minikube, which you could simply activate the Kubernetes feature on your docker-desktop UI:

enable-kubernetes

once it is setup you can right click on the docker desktop icon > Kubernetes docker-desktop

To verify now that your deployement/service works properly:

kubectl apply -f /file.yaml
Affes Salem
  • 1,303
  • 10
  • 26
  • Thanks for your answer. I was confused why I am not able to access minikube IP from my host machine i.e. WINDOWS – Deepak Rai May 08 '23 at 09:22
0

If you are running minikube in a Windows, then minikube must run as an Administrator command prompt window.