2019-03-10 19:02:52 +00:00
# Networking
2017-05-03 21:53:51 +00:00
The minikube VM is exposed to the host system via a host-only IP address, that can be obtained with the `minikube ip` command.
Any services of type `NodePort` can be accessed over that IP address, on the NodePort.
2018-02-27 17:54:00 +00:00
To determine the NodePort for your service, you can use a `kubectl` command like this (note that `nodePort` begins with lowercase `n` in JSON output):
2017-05-03 21:53:51 +00:00
2018-02-27 17:54:00 +00:00
`kubectl get service $SERVICE --output='jsonpath="{.spec.ports[0].nodePort}"'`
2017-12-12 14:48:04 +00:00
We also have a shortcut for fetching the minikube IP and a service's `NodePort` :
`minikube service --url $SERVICE`
2018-10-18 18:01:47 +00:00
2019-03-10 19:02:52 +00:00
## LoadBalancer emulation (`minikube tunnel`)
2018-10-18 18:01:47 +00:00
2019-03-10 19:02:52 +00:00
Services of type `LoadBalancer` can be exposed via the `minikube tunnel` command.
2018-10-18 18:01:47 +00:00
````shell
minikube tunnel
2019-03-10 19:02:52 +00:00
````
2018-10-18 18:01:47 +00:00
Will output:
2019-03-10 19:02:52 +00:00
```text
2018-10-18 18:01:47 +00:00
out/minikube tunnel
Password: ** ***
2019-03-10 19:02:52 +00:00
Status:
2018-10-18 18:01:47 +00:00
machine: minikube
pid: 59088
route: 10.96.0.0/12 -> 192.168.99.101
minikube: Running
services: []
2019-03-10 19:02:52 +00:00
errors:
2018-10-18 18:01:47 +00:00
minikube: no errors
router: no errors
loadbalancer emulator: no errors
2019-03-10 19:02:52 +00:00
````
2018-10-18 18:01:47 +00:00
Tunnel might ask you for password for creating and deleting network routes.
2019-03-10 19:02:52 +00:00
## Cleaning up orphaned routes
2018-10-18 18:01:47 +00:00
If the `minikube tunnel` shuts down in an unclean way, it might leave a network route around.
2019-03-10 19:02:52 +00:00
This case the ~/.minikube/tunnels.json file will contain an entry for that tunnel.
To cleanup orphaned routes, run:
````shell
2018-10-18 18:01:47 +00:00
minikube tunnel --cleanup
````
2019-03-10 19:02:52 +00:00
## (Advanced) Running tunnel as root to avoid entering password multiple times
2018-10-18 18:01:47 +00:00
2019-03-10 19:02:52 +00:00
`minikube tunnel` runs as a separate daemon, creates a network route on the host to the service CIDR of the cluster using the cluster's IP address as a gateway.
Adding a route requires root privileges for the user, and thus there are differences in how to run `minikube tunnel` depending on the OS.
2018-10-18 18:01:47 +00:00
2019-03-10 19:02:52 +00:00
Recommended way to use on Linux with KVM2 driver and MacOSX with Hyperkit driver:
2018-10-18 18:01:47 +00:00
`sudo -E minikube tunnel`
2019-03-10 19:02:52 +00:00
Using VirtualBox on Windows, Mac and Linux _both_ `minikube start` and `minikube tunnel` needs to be started from the same Administrator user session otherwise [VBoxManage can't recognize the created VM ](https://forums.virtualbox.org/viewtopic.php?f=6&t=81551 ).