Skip to content

Commit

Permalink
Merge pull request #6306 from medyagh/tunnel_example
Browse files Browse the repository at this point in the history
Add a clear example of minikube tunnel to the docs
  • Loading branch information
medyagh authored Jan 15, 2020
2 parents 3ea7d42 + b9d36af commit cdafd16
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var cleanup bool
var tunnelCmd = &cobra.Command{
Use: "tunnel",
Short: "tunnel makes services of type LoadBalancer accessible on localhost",
Long: `tunnel creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP`,
Long: `tunnel creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP. for a detailed example see https://minikube.sigs.k8s.io/docs/tasks/loadbalancer`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
RootCmd.PersistentPreRun(cmd, args)
},
Expand Down
80 changes: 62 additions & 18 deletions site/content/en/docs/Tasks/loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,75 @@ A LoadBalancer service is the standard way to expose a service to the internet.

## Using `minikube tunnel`

Services of type `LoadBalancer` can be exposed via the `minikube tunnel` command. It will run until Ctrl-C is hit.
Services of type `LoadBalancer` can be exposed via the `minikube tunnel` command. It will run in a separate terminal until Ctrl-C is hit.

````shell
## Example

#### Run tunnel in a separate terminal
it will ask for password.

```
minikube tunnel
````
Example output:
```

```text
out/minikube tunnel
Password: *****
Status:
machine: minikube
pid: 59088
route: 10.96.0.0/12 -> 192.168.99.101
minikube: Running
services: []
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
`minikube tunnel` runs as a separate daemon, creating a network route on the host to the service CIDR of the cluster using the cluster's IP address as a gateway. The tunnel command exposes the external IP directly to any program running on the host operating system.


<details>
<summary>
tunnel output example
</summary>
<pre>
Password:
Status:
machine: minikube
pid: 39087
route: 10.96.0.0/12 -> 192.168.64.194
minikube: Running
services: [hello-minikube]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
...
...
...
</pre>
</details>


#### Create a kubernetes deployment
```
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4
```
#### Create a kubernetes service type LoadBalancer
```
kubectl expose deployment hello-minikube1 --type=LoadBalancer --port=8080
```

### Check external IP
```
kubectl get svc
```
<pre>
$ kc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube1 LoadBalancer 10.96.184.178 10.96.184.178 8080:30791/TCP 40s
</pre>

`minikube tunnel` runs as a separate daemon, creating a network route on the host to the service CIDR of the cluster using the cluster's IP address as a gateway. The tunnel command exposes the external IP directly to any program running on the host operating system.

note that without minikube tunnel, it would kubernetes would be showing external IP as "pending".

### Try in your browser
open in your browser (make sure there is no proxy set)
```
http://REPLACE_WITH_EXTERNAL_IP:8080
```


Each service will get it's own external ip.

----
### DNS resolution (experimental)

If you are on macOS, the tunnel command also allows DNS resolution for Kubernetes services from the host.
Expand Down

0 comments on commit cdafd16

Please sign in to comment.