Skip to content

Commit 2b16bfd

Browse files
committed
update service doc
1 parent aaf7c5c commit 2b16bfd

File tree

1 file changed

+128
-60
lines changed

1 file changed

+128
-60
lines changed

site/content/en/docs/handbook/accessing.md

+128-60
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,77 @@ A NodePort service is the most basic way to get external traffic directly to you
2525
We also have a shortcut for fetching the minikube IP and a service's `NodePort`:
2626

2727
```shell
28-
minikube service --url <service-name>
28+
minikube service <service-name> --url
2929
```
3030

31-
## Getting the NodePort using kubectl
31+
### Using `minikube service` with tunnel
32+
33+
The network is limited if you are using a Docker driver on darwin, Windows or WSL, and the Node IP is not reachable directly.
34+
35+
If minikube runs on Linux with Docker driver, no tunnel will be created.
36+
37+
Services of type `NodePort` can be exposed via the `minikube service <service-name> --url` command. It must be run in a separate terminal window to keep the [tunnel](https://en.wikipedia.org/wiki/Port_forwarding#Local_port_forwarding) open. Ctrl-C in the terminal can be used to terminate the process at which time the network routes will be cleaned up.
38+
39+
### Example of NodePort
40+
41+
1. Create a kubernetes deployment
42+
43+
```shell
44+
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4
45+
```
46+
47+
2. Create a kubernetes service type NodePort
48+
49+
```shell
50+
kubectl expose deployment hello-minikube1 --type=NodePort --port=8080
51+
```
52+
53+
3. Check Node Port
54+
55+
```shell
56+
kubectl get svc
57+
```
58+
<pre>
59+
$ kc get svc
60+
AME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
61+
hello-minikube1 NodePort 10.100.238.34 <none> 8080:31389/TCP 3s
62+
</pre>
63+
64+
4. Run service tunnel
65+
66+
```shell
67+
minikube service hello-minikube1 --url
68+
```
69+
70+
`minikube service hello-minikube1 --url` runs as a process, creating a [tunnel](https://en.wikipedia.org/wiki/Port_forwarding#Local_port_forwarding) to cluster. The command exposes the service directly to any program running on the host operating system.
71+
72+
<details>
73+
<summary>
74+
service output example
75+
</summary>
76+
<pre>
77+
$ minikube service hello-minikube1 --url
78+
http://127.0.0.1:57123
79+
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
80+
</pre>
81+
</details>
82+
83+
check ssh tunnel in another terminal
84+
85+
```shell
86+
$ ps -ef | grep [email protected]
87+
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -N [email protected] -p 55972 -i /Users/FOO/.minikube/machines/minikube/id_rsa -L TUNNEL_PORT:CLUSTER_IP:TARGET_PORT
88+
```
89+
90+
5. Try in your browser
91+
92+
open in your browser (make sure there is no proxy set)
93+
94+
```shell
95+
http://127.0.0.1:TUNNEL_PORT
96+
```
97+
98+
### Getting the NodePort using kubectl
3299

33100
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.
34101

@@ -54,77 +121,78 @@ This flag also accepts a comma separated list of ports and port ranges.
54121

55122
A LoadBalancer service is the standard way to expose a service to the internet. With this method, each service gets its own IP address.
56123

57-
## Using `minikube tunnel`
124+
### Using `minikube tunnel`
58125

59126
Services of type `LoadBalancer` can be exposed via the `minikube tunnel` command. It must be run in a separate terminal window to keep the `LoadBalancer` running. Ctrl-C in the terminal can be used to terminate the process at which time the network routes will be cleaned up.
60127

61-
## Example
128+
### Example of LoadBalancer
62129

63-
#### Run tunnel in a separate terminal
130+
1. Run tunnel in a separate terminal
64131

65-
it will ask for password.
132+
it will ask for password.
66133

67-
```shell
68-
minikube tunnel
69-
```
134+
```shell
135+
minikube tunnel
136+
```
70137

71-
`minikube tunnel` runs as a process, 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.
72-
73-
<details>
74-
<summary>
75-
tunnel output example
76-
</summary>
77-
<pre>
78-
Password:
79-
Status:
80-
machine: minikube
81-
pid: 39087
82-
route: 10.96.0.0/12 -> 192.168.64.194
83-
minikube: Running
84-
services: [hello-minikube]
85-
errors:
86-
minikube: no errors
87-
router: no errors
88-
loadbalancer emulator: no errors
89-
...
90-
...
91-
...
92-
</pre>
93-
</details>
94-
95-
#### Create a kubernetes deployment
138+
`minikube tunnel` runs as a process, 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.
96139
97-
```shell
98-
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4
99-
```
140+
<details>
141+
<summary>
142+
tunnel output example
143+
</summary>
144+
<pre>
145+
Password:
146+
Status:
147+
machine: minikube
148+
pid: 39087
149+
route: 10.96.0.0/12 -> 192.168.64.194
150+
minikube: Running
151+
services: [hello-minikube]
152+
errors:
153+
minikube: no errors
154+
router: no errors
155+
loadbalancer emulator: no errors
156+
...
157+
...
158+
...
159+
</pre>
160+
</details>
100161
101-
#### Create a kubernetes service type LoadBalancer
162+
2. Create a kubernetes deployment
102163
103-
```shell
104-
kubectl expose deployment hello-minikube1 --type=LoadBalancer --port=8080
105-
```
164+
```shell
165+
kubectl create deployment hello-minikube1 --image=k8s.gcr.io/echoserver:1.4
166+
```
106167
107-
### Check external IP
168+
3. Create a kubernetes service type LoadBalancer
108169
109-
```shell
110-
kubectl get svc
111-
```
112-
<pre>
113-
$ kc get svc
114-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
115-
hello-minikube1 LoadBalancer 10.96.184.178 10.96.184.178 8080:30791/TCP 40s
116-
</pre>
170+
```shell
171+
kubectl expose deployment hello-minikube1 --type=LoadBalancer --port=8080
172+
```
117173
118-
note that without minikube tunnel, kubernetes would be showing external IP as "pending".
174+
4. Check external IP
119175
120-
### Try in your browser
176+
```shell
177+
kubectl get svc
178+
```
179+
<pre>
180+
$ kc get svc
181+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
182+
hello-minikube1 LoadBalancer 10.96.184.178 10.96.184.178 8080:30791/TCP 40s
183+
</pre>
121184
122-
open in your browser (make sure there is no proxy set)
123-
```
124-
http://REPLACE_WITH_EXTERNAL_IP:8080
125-
```
185+
note that without minikube tunnel, kubernetes would be showing external IP as "pending".
186+
187+
5. Try in your browser
188+
189+
open in your browser (make sure there is no proxy set)
126190
127-
Each service will get its own external ip.
191+
```shell
192+
http://REPLACE_WITH_EXTERNAL_IP:8080
193+
```
194+
195+
Each service will get its own external ip.
128196
129197
----
130198
@@ -150,12 +218,12 @@ Adding a route requires root privileges for the user, and thus there are differe
150218
151219
<https://superuser.com/questions/1328452/sudoers-nopasswd-for-single-executable-but-allowing-others>
152220
153-
154221
### Access to ports <1024 on Windows requires root permission
222+
155223
If you are using Docker driver on Windows, there is a chance that you have an old version of SSH client you might get an error like - `Privileged ports can only be forwarded by root.` or you might not be able to access the service even after `minikube tunnel` if the access port is less than 1024 but for ports greater than 1024 works fine.
156224
157225
In order to resolve this, ensure that you are running the latest version of SSH client. You can install the latest version of the SSH client on Windows by running the following in a Command Prompt with an Administrator Privileges (Requires [chocolatey package manager](https://chocolatey.org/install))
158-
```
226+
```cmd
159227
choco install openssh
160228
```
161-
The latest version (`OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5`) which is available on Windows 10 by default doesn't work. You can track the issue with this over here - https://github.com/PowerShell/Win32-OpenSSH/issues/1693
229+
The latest version (`OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5`) which is available on Windows 10 by default doesn't work. You can track the issue with this over here - https://github.com/PowerShell/Win32-OpenSSH/issues/1693

0 commit comments

Comments
 (0)