@@ -38,6 +38,18 @@ Visit [Install tools](/docs/tasks/tools/#minikube) to learn how to install `mini
38
38
本教程假设你正在使用 ` minikube ` 运行一个本地 Kubernetes 集群。
39
39
参阅[ 安装工具] ( /zh-cn/docs/tasks/tools/#minikube ) 了解如何安装 ` minikube ` 。
40
40
41
+ {{< note >}}
42
+ <!--
43
+ This tutorial uses a container that requires the AMD64 architecture.
44
+ If you are using minikube on a computer with a different CPU architecture,
45
+ you could try using minikube with a driver that can emulate AMD64.
46
+ For example, the Docker Desktop driver can do this.
47
+ -->
48
+ 本教程使用需要 AMD64 架构的容器。
49
+ 如果你在其他 CPU 架构的计算机上使用 minikube,可以尝试使用带有可以模拟 AMD64 的驱动程序的 minikube。
50
+ 例如,Docker Desktop 驱动程序可以执行此操作。
51
+ {{< /note >}}
52
+
41
53
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
42
54
43
55
<!--
@@ -119,6 +131,24 @@ If you haven't already set up a cluster locally, run `minikube start` to create
119
131
deployment.apps/web created
120
132
```
121
133
134
+ <!--
135
+ Verify that the Deployment is in a Ready state:
136
+ -->
137
+ 验证 Deployment 是否处于 Ready 状态:
138
+
139
+ ``` shell
140
+ kubectl get deployment web
141
+ ```
142
+ <!--
143
+ The output should be similar to:
144
+ -->
145
+ 输出应类似于:
146
+
147
+ ``` none
148
+ NAME READY UP-TO-DATE AVAILABLE AGE
149
+ web 1/1 1 1 53s
150
+ ```
151
+
122
152
<!--
123
153
1. Expose the Deployment:
124
154
-->
@@ -157,9 +187,14 @@ If you haven't already set up a cluster locally, run `minikube start` to create
157
187
```
158
188
159
189
<!--
160
- 1. Visit the Service via NodePort:
190
+ 1. Visit the Service via NodePort, using the [`minikube service`](https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-service-with-tunnel) command. Follow the instructions for your platform :
161
191
-->
162
- 4 . 使用节点端口信息访问服务:
192
+ 4 . 使用节点端口信息访问服务,使用
193
+ [ ` minikube service ` ] ( https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-service-with-tunnel ) 命令。
194
+ 请按照适合你平台的说明进行操作:
195
+
196
+ {{< tabs name="minikube_service" >}}
197
+ {{% tab name="Linux" %}}
163
198
164
199
``` shell
165
200
minikube service web --url
@@ -174,10 +209,49 @@ If you haven't already set up a cluster locally, run `minikube start` to create
174
209
http://172.17.0.15:31637
175
210
```
176
211
212
+ <!--
213
+ Invoke the URL obtained in the output of the previous step:
214
+ -->
215
+ 调用上一步输出中获取的 URL:
216
+
177
217
``` shell
178
218
curl http://172.17.0.15:31637
179
219
```
180
220
221
+ {{% /tab %}}
222
+ {{% tab name="MacOS" %}}
223
+
224
+ <!--
225
+ # The command must be run in a separate terminal.
226
+ -->
227
+ ``` shell
228
+ # 该命令必须在单独的终端中运行。
229
+ minikube service web --url
230
+ ```
231
+
232
+ <!--
233
+ The output is similar to:
234
+ -->
235
+ 输出类似于:
236
+
237
+ ``` none
238
+ http://127.0.0.1:62445
239
+ ! Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
240
+ ```
241
+
242
+ <!--
243
+ From a different terminal, invoke the URL obtained in the output of the previous step:
244
+ -->
245
+ 从不同的终端调用在上一步的输出中获取的 URL:
246
+
247
+ ``` shell
248
+ curl http://127.0.0.1:62445
249
+ ```
250
+
251
+ {{% /tab %}}
252
+ {{< /tabs >}}
253
+ <br >
254
+
181
255
<!--
182
256
The output is similar to:
183
257
-->
@@ -200,13 +274,13 @@ If you haven't already set up a cluster locally, run `minikube start` to create
200
274
## Create an Ingress
201
275
202
276
The following manifest defines an Ingress that sends traffic to your Service via
203
- `hello-world.info `.
277
+ `hello-world.example `.
204
278
205
279
1. Create `example-ingress.yaml` from the following file:
206
280
-->
207
281
## 创建一个 Ingress {#create-ingress}
208
282
209
- 下面是一个定义 Ingress 的配置文件,负责通过 ` hello-world.info `
283
+ 下面是一个定义 Ingress 的配置文件,负责通过 ` hello-world.example `
210
284
将请求转发到你的服务。
211
285
212
286
1 . 根据下面的 YAML 创建文件 ` example-ingress.yaml ` :
@@ -253,19 +327,67 @@ The following manifest defines an Ingress that sends traffic to your Service via
253
327
接下来你将会在 ` ADDRESS ` 列中看到 IPv4 地址,例如:
254
328
255
329
``` none
256
- NAME CLASS HOSTS ADDRESS PORTS AGE
257
- example-ingress <none> hello-world.info 172.17.0.15 80 38s
330
+ NAME CLASS HOSTS ADDRESS PORTS AGE
331
+ example-ingress nginx hello-world.example 172.17.0.15 80 38s
258
332
```
259
333
260
334
<!--
261
- 1. Verify that the Ingress controller is directing traffic:
335
+ 1. Verify that the Ingress controller is directing traffic, by following the instructions for your platform :
262
336
-->
263
- 4 . 验证 Ingress 控制器能够转发请求流量:
337
+ 4 . 验证 Ingress 控制器能够转发请求流量,按照适用于所属平台的说明进行操作:
338
+
339
+ {{< note >}}
340
+ <!--
341
+ The network is limited if using the Docker driver on MacOS (Darwin) and the Node IP is not reachable directly. To get ingress to work you’ll need to open a new terminal and run `minikube tunnel`.
342
+ `sudo` permission is required for it, so provide the password when prompted.
343
+ -->
344
+ 如果在 MacOS(Darwin)上使用 Docker 驱动程序,网络会受到限制,并且无法直接访问节点 IP。
345
+ 要让 Ingress 正常工作,你需要打开一个新终端并运行 ` minikube tunnel ` 。
346
+ 此操作需要 ` sudo ` 权限,因此请在出现提示时提供密码。
347
+ {{< /note >}}
348
+
349
+ {{< tabs name="ingress" >}}
350
+ {{% tab name="Linux" %}}
264
351
265
352
``` shell
266
- curl --resolve " hello-world.info:80:$( minikube ip ) " -i http://hello-world.info
353
+ curl --resolve " hello-world.example:80:$( minikube ip ) " -i http://hello-world.example
354
+ ```
355
+
356
+ {{% /tab %}}
357
+ {{% tab name="MacOS" %}}
358
+
359
+ ``` shell
360
+ minikube tunnel
361
+ ```
362
+
363
+ <!--
364
+ The output is similar to:
365
+ -->
366
+ 输出类似于:
367
+
368
+ ``` none
369
+ Tunnel successfully started
370
+
371
+ NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...
372
+
373
+ The service/ingress example-ingress requires privileged ports to be exposed: [80 443]
374
+ sudo permission will be asked for it.
375
+ Starting tunnel for service example-ingress.
267
376
```
268
377
378
+ <!--
379
+ From within a new terminal, invoke the following command:
380
+ -->
381
+ 从新终端中调用以下命令:
382
+
383
+ ``` shell
384
+ curl --resolve " hello-world.example:80:127.0.0.1" -i http://hello-world.example
385
+ ```
386
+
387
+ {{% /tab %}}
388
+ {{< /tabs >}}
389
+ <br >
390
+
269
391
<!--
270
392
You should see:
271
393
-->
@@ -307,10 +429,12 @@ The following manifest defines an Ingress that sends traffic to your Service via
307
429
` ` `
308
430
309
431
{{< note > }}
432
+
310
433
< ! --
311
434
Change the IP address to match the output from ` minikube ip` .
312
435
-->
313
- 更改 IP 地址以匹配 ` minikube ip` 的输出。
436
+
437
+ 更改 IP 地址以匹配 ` minikube ip` 的输出。
314
438
{{< /note > }}
315
439
316
440
< ! --
@@ -342,6 +466,25 @@ The following manifest defines an Ingress that sends traffic to your Service via
342
466
deployment.apps/web2 created
343
467
` ` `
344
468
469
+ < ! --
470
+ Verify that the Deployment is in a Ready state:
471
+ -->
472
+ 验证 Deployment 是否处于 Ready 状态:
473
+
474
+ ` ` ` shell
475
+ kubectl get deployment web2
476
+ ` ` `
477
+
478
+ < ! --
479
+ The output should be similar to:
480
+ -->
481
+ 输出应类似于:
482
+
483
+ ` ` ` none
484
+ NAME READY UP-TO-DATE AVAILABLE AGE
485
+ web2 1/1 1 1 16s
486
+ ` ` `
487
+
345
488
< ! --
346
489
1. Expose the second Deployment:
347
490
-->
@@ -407,10 +550,48 @@ The following manifest defines an Ingress that sends traffic to your Service via
407
550
408
551
1. 访问 Hello World 应用的第一个版本:
409
552
553
+ {{< tabs name=" ingress2-v1" > }}
554
+ {{% tab name=" Linux" %}}
555
+
556
+ ` ` ` shell
557
+ curl --resolve " hello-world.example:80:$( minikube ip ) " -i http://hello-world.example
558
+ ` ` `
559
+
560
+ {{% /tab %}}
561
+ {{% tab name=" MacOS" %}}
562
+
563
+ ` ` ` shell
564
+ minikube tunnel
565
+ ` ` `
566
+
567
+ < ! --
568
+ The output is similar to:
569
+ -->
570
+ 输出类似于:
571
+
572
+ ` ` ` none
573
+ Tunnel successfully started
574
+
575
+ NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...
576
+
577
+ The service/ingress example-ingress requires privileged ports to be exposed: [80 443]
578
+ sudo permission will be asked for it.
579
+ Starting tunnel for service example-ingress.
580
+ ` ` `
581
+
582
+ < ! --
583
+ From within a new terminal, invoke the following command:
584
+ -->
585
+ 从新终端中调用以下命令:
586
+
410
587
` ` ` shell
411
- curl --resolve " hello-world.info :80:$( minikube ip ) " -i http://hello-world.info
588
+ curl --resolve " hello-world.example :80:127.0.0.1 " -i http://hello-world.example
412
589
` ` `
413
590
591
+ {{% /tab %}}
592
+ {{< /tabs > }}
593
+ < br>
594
+
414
595
< ! --
415
596
The output is similar to:
416
597
-->
@@ -427,9 +608,46 @@ The following manifest defines an Ingress that sends traffic to your Service via
427
608
-->
428
609
2. 访问 Hello World 应用的第二个版本:
429
610
611
+ {{< tabs name=" ingress2-v2" > }}
612
+ {{% tab name=" Linux" %}}
613
+
614
+ ` ` ` shell
615
+ curl --resolve " hello-world.example:80:$( minikube ip ) " -i http://hello-world.example/v2
616
+ ` ` `
617
+
618
+ {{% /tab %}}
619
+ {{% tab name=" MacOS" %}}
620
+
430
621
` ` ` shell
431
- curl --resolve " hello-world.info:80: $( minikube ip ) " -i http://hello-world.info/v2
622
+ minikube tunnel
432
623
` ` `
624
+
625
+ < ! --
626
+ The output is similar to:
627
+ -->
628
+ 输出类似于:
629
+
630
+ ` ` ` none
631
+ Tunnel successfully started
632
+
633
+ NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...
634
+
635
+ The service/ingress example-ingress requires privileged ports to be exposed: [80 443]
636
+ sudo permission will be asked for it.
637
+ Starting tunnel for service example-ingress.
638
+ ` ` `
639
+
640
+ < ! --
641
+ From within a new terminal, invoke the following command:
642
+ -->
643
+ 从新终端中调用以下命令:
644
+
645
+ ` ` ` shell
646
+ curl --resolve " hello-world.example:80:127.0.0.1" -i http://hello-world.example/v2
647
+ ` ` `
648
+
649
+ {{% /tab %}}
650
+ {{< /tabs > }}
433
651
434
652
< ! --
435
653
The output is similar to:
@@ -444,11 +662,11 @@ The following manifest defines an Ingress that sends traffic to your Service via
444
662
445
663
{{< note > }}
446
664
< ! --
447
- If you did the optional step to update ` /etc/hosts` , you can also visit ` hello-world.info ` and
448
- ` hello-world.info /v2` from your browser.
665
+ If you did the optional step to update ` /etc/hosts` , you can also visit ` hello-world.example ` and
666
+ ` hello-world.example /v2` from your browser.
449
667
-->
450
668
如果你执行了更新 ` /etc/hosts` 的可选步骤,你也可以从你的浏览器中访问
451
- ` hello-world.info ` 和 ` hello-world.info /v2` 。
669
+ ` hello-world.example ` 和 ` hello-world.example /v2` 。
452
670
{{< /note > }}
453
671
454
672
# # {{% heading "whatsnext" %}}
0 commit comments