Skip to content

Commit a1331a2

Browse files
authored
Merge pull request #24774 from tengqm/fix-21226
Resync tutorial page expose external IP address
2 parents 04b4e4c + f1e5b34 commit a1331a2

File tree

1 file changed

+112
-113
lines changed

1 file changed

+112
-113
lines changed

content/zh/docs/tutorials/stateless-application/expose-external-ip-address.md

Lines changed: 112 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ title: 公开外部 IP 地址以访问集群中应用程序
33
content_type: tutorial
44
weight: 10
55
---
6-
76
<!--
8-
---
97
title: Exposing an External IP Address to Access an Application in a Cluster
108
content_type: tutorial
119
weight: 10
12-
---
1310
-->
1411

1512
<!-- overview -->
@@ -20,12 +17,8 @@ external IP address.
2017
-->
2118
此页面显示如何创建公开外部 IP 地址的 Kubernetes 服务对象。
2219

23-
24-
25-
2620
## {{% heading "prerequisites" %}}
2721

28-
2922
<!--
3023
* Install [kubectl](/docs/tasks/tools/install-kubectl/).
3124
@@ -40,30 +33,23 @@ external IP address.
4033

4134
* 安装 [kubectl](/zh/docs/tasks/tools/install-kubectl/).
4235

43-
* 使用 Google Kubernetes Engine 或 Amazon Web Services 等云供应商创建 Kubernetes 群集。
44-
本教程创建了一个[外部负载均衡器](/zh/docs/tasks/access-application-cluster/create-external-load-balancer/),需要云供应商。
36+
* 使用 Google Kubernetes Engine 或 Amazon Web Services 等云供应商创建 Kubernetes 集群。
37+
本教程创建了一个[外部负载均衡器](/zh/docs/tasks/access-application-cluster/create-external-load-balancer/)
38+
需要云供应商。
4539

4640
* 配置 `kubectl` 与 Kubernetes API 服务器通信。有关说明,请参阅云供应商文档。
4741

48-
49-
50-
5142
## {{% heading "objectives" %}}
5243

53-
5444
<!--
5545
* Run five instances of a Hello World application.
5646
* Create a Service object that exposes an external IP address.
5747
* Use the Service object to access the running application.
5848
-->
59-
6049
* 运行 Hello World 应用程序的五个实例。
6150
* 创建一个公开外部 IP 地址的 Service 对象。
6251
* 使用 Service 对象访问正在运行的应用程序。
6352

64-
65-
66-
6753
<!-- lessoncontent -->
6854

6955
<!--
@@ -77,118 +63,130 @@ external IP address.
7763
-->
7864
1. 在集群中运行 Hello World 应用程序:
7965

80-
{{< codenew file="service/load-balancer-example.yaml" >}}
81-
82-
```shell
83-
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
84-
```
85-
86-
<!--
87-
The preceding command creates a
88-
[Deployment](/docs/concepts/workloads/controllers/deployment/)
89-
object and an associated
90-
[ReplicaSet](/docs/concepts/workloads/controllers/replicaset/)
91-
object. The ReplicaSet has five
92-
[Pods](/docs/concepts/workloads/pods/pod/),
93-
each of which runs the Hello World application.
94-
-->
95-
前面的命令创建一个 [Deployment](/zh/docs/concepts/workloads/controllers/deployment/)
96-
对象和一个关联的 [ReplicaSet](/zh/docs/concepts/workloads/controllers/replicaset/)对象。
97-
ReplicaSet 有五个 [Pod](/zh/docs/concepts/workloads/pods/pod/),每个都运行 Hello World 应用程序。
66+
{{< codenew file="service/load-balancer-example.yaml" >}}
67+
68+
```shell
69+
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
70+
```
71+
72+
<!--
73+
The preceding command creates a
74+
{{< glossary_tooltip text="Deployment" term_id="deployment" >}}
75+
and an associated
76+
{{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}}.
77+
The ReplicaSet has five
78+
{{< glossary_tooltip text="Pods" term_id="pod" >}}
79+
each of which runs the Hello World application.
80+
-->
81+
前面的命令创建一个
82+
{{< glossary_tooltip text="Deployment" term_id="deployment" >}}
83+
对象和一个关联的
84+
{{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}} 对象。
85+
ReplicaSet 有五个 {{< glossary_tooltip text="Pods" term_id="pod" >}},
86+
每个都运行 Hello World 应用程序。
9887

9988
<!--
10089
1. Display information about the Deployment:
10190
-->
10291
2. 显示有关 Deployment 的信息:
10392

104-
kubectl get deployments hello-world
105-
kubectl describe deployments hello-world
93+
```shell
94+
kubectl get deployments hello-world
95+
kubectl describe deployments hello-world
96+
```
10697

10798
<!--
10899
1. Display information about your ReplicaSet objects:
109100
-->
110101
3. 显示有关 ReplicaSet 对象的信息:
111102

112-
kubectl get replicasets
113-
kubectl describe replicasets
103+
```shell
104+
kubectl get replicasets
105+
kubectl describe replicasets
106+
```
114107

115108
<!--
116109
1. Create a Service object that exposes the deployment:
117110
-->
118-
4. 创建公开 deployment 的 Service 对象:
111+
4. 创建公开 Deployment 的 Service 对象:
119112

120-
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
113+
```shell
114+
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
115+
```
121116

122117
<!--
123118
1. Display information about the Service:
124119
-->
125120
5. 显示有关 Service 的信息:
126121

127-
kubectl get services my-service
122+
```shell
123+
kubectl get services my-service
124+
```
128125

129-
<!--
126+
<!--
130127
The output is similar to this:
131-
-->
128+
-->
132129
输出类似于:
133130

134-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
135-
my-service ClusterIP 10.3.245.137 104.198.205.71 8080/TCP 54s
136-
137-
<!--
138-
{{< note >}}
139-
140-
The `type=LoadBalancer` service is backed by external cloud providers, which is not covered in this example, please refer to [this page](/docs/concepts/services-networking/service/#loadbalancer) for the details.
141-
142-
{{< /note >}}
143-
-->
144-
注意:`type=LoadBalancer` 服务由外部云服务提供商提供支持,本例中不包含此部分,详细信息请参考[此页](/docs/concepts/services-networking/service/#loadbalancer)
145-
146-
<!--
147-
{{< note >}}
148-
149-
If the external IP address is shown as \<pending\>, wait for a minute and enter the same command again.
150-
151-
{{< /note >}}
152-
-->
153-
注意:如果外部 IP 地址显示为 \<pending\>,请等待一分钟再次输入相同的命令。
131+
```
132+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
133+
my-service ClusterIP 10.3.245.137 104.198.205.71 8080/TCP 54s
134+
```
135+
136+
<!--
137+
{{< note >}}
138+
The `type=LoadBalancer` service is backed by external cloud providers, which is not covered in this example, please refer to [this page](/docs/concepts/services-networking/service/#loadbalancer) for the details.
139+
{{< /note >}}
140+
-->
141+
提示:`type=LoadBalancer` 服务由外部云服务提供商提供支持,本例中不包含此部分,
142+
详细信息请参考[此页](/docs/concepts/services-networking/service/#loadbalancer)
143+
144+
<!--
145+
{{< note >}}
146+
If the external IP address is shown as \<pending\>, wait for a minute and enter the same command again.
147+
{{< /note >}}
148+
-->
149+
提示:如果外部 IP 地址显示为 \<pending\>,请等待一分钟再次输入相同的命令。
154150

155151
<!--
156152
1. Display detailed information about the Service:
157153
-->
158154
6. 显示有关 Service 的详细信息:
159155

160-
kubectl describe services my-service
156+
```shell
157+
kubectl describe services my-service
158+
```
161159

162-
<!--
160+
<!--
163161
The output is similar to this:
164-
-->
162+
-->
165163
输出类似于:
166164

167-
Name: my-service
168-
Namespace: default
169-
Labels: run=load-balancer-example
170-
Annotations: <none>
171-
Selector: run=load-balancer-example
172-
Type: LoadBalancer
173-
IP: 10.3.245.137
174-
LoadBalancer Ingress: 104.198.205.71
175-
Port: <unset> 8080/TCP
176-
NodePort: <unset> 32377/TCP
177-
Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
178-
Session Affinity: None
179-
Events: <none>
180-
181-
<!--
165+
```
166+
Name: my-service
167+
Namespace: default
168+
Labels: run=load-balancer-example
169+
Annotations: <none>
170+
Selector: run=load-balancer-example
171+
Type: LoadBalancer
172+
IP: 10.3.245.137
173+
LoadBalancer Ingress: 104.198.205.71
174+
Port: <unset> 8080/TCP
175+
NodePort: <unset> 32377/TCP
176+
Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
177+
Session Affinity: None
178+
Events: <none>
179+
```
180+
<!--
182181
Make a note of the external IP address (`LoadBalancer Ingress`) exposed by
183182
your service. In this example, the external IP address is 104.198.205.71.
184183
Also note the value of `Port` and `NodePort`. In this example, the `Port`
185184
is 8080 and the `NodePort` is 32377.
186-
-->
185+
-->
187186
记下服务公开的外部 IP 地址(`LoadBalancer Ingress`)。
188187
在本例中,外部 IP 地址是 104.198.205.71。还要注意 `Port``NodePort` 的值。
189188
在本例中,`Port` 是 8080,`NodePort` 是32377。
190189

191-
192190
<!--
193191
1. In the preceding output, you can see that the service has several endpoints:
194192
10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more. These are internal
@@ -200,78 +198,79 @@ If the external IP address is shown as \<pending\>, wait for a minute and enter
200198
这些都是正在运行 Hello World 应用程序的 pod 的内部地址。
201199
要验证这些是 pod 地址,请输入以下命令:
202200

203-
kubectl get pods --output=wide
201+
```shell
202+
kubectl get pods --output=wide
203+
```
204204

205-
<!--
205+
<!--
206206
The output is similar to this:
207-
-->
207+
-->
208208
输出类似于:
209209

210-
NAME ... IP NODE
211-
hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
212-
hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
213-
hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a
214-
hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc
215-
hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
216-
210+
```
211+
NAME ... IP NODE
212+
hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
213+
hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
214+
hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a
215+
hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc
216+
hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
217+
```
217218
<!--
218219
1. Use the external IP address (`LoadBalancer Ingress`) to access the Hello
219220
World application:
220221
-->
221222
8. 使用外部 IP 地址(`LoadBalancer Ingress`)访问 Hello World 应用程序:
222223

223-
curl http://<external-ip>:<port>
224+
```shell
225+
curl http://<external-ip>:<port>
226+
```
224227

225-
<!--
228+
<!--
226229
where `<external-ip>` is the external IP address (`LoadBalancer Ingress`)
227230
of your Service, and `<port>` is the value of `Port` in your Service
228231
description.
229232
If you are using minikube, typing `minikube service my-service` will
230233
automatically open the Hello World application in a browser.
231-
-->
234+
-->
232235
其中 `<external-ip>` 是您的服务的外部 IP 地址(`LoadBalancer Ingress`),
233236
`<port>` 是您的服务描述中的 `port` 的值。
234237
如果您正在使用 minikube,输入 `minikube service my-service` 将在浏览器中自动打开 Hello World 应用程序。
235238

236-
<!--
239+
<!--
237240
The response to a successful request is a hello message:
238-
-->
241+
-->
239242
成功请求的响应是一条问候消息:
240243

241-
Hello Kubernetes!
242-
243-
244-
244+
```
245+
Hello Kubernetes!
246+
```
245247

246248
## {{% heading "cleanup" %}}
247249

248-
249250
<!--
250251
To delete the Service, enter this command:
251252
-->
252253
要删除服务,请输入以下命令:
253254

254-
kubectl delete services my-service
255+
```shell
256+
kubectl delete services my-service
257+
```
255258

256259
<!--
257260
To delete the Deployment, the ReplicaSet, and the Pods that are running
258261
the Hello World application, enter this command:
259262
-->
260263
要删除正在运行 Hello World 应用程序的 Deployment,ReplicaSet 和 Pod,请输入以下命令:
261264

262-
kubectl delete deployment hello-world
263-
264-
265-
265+
```shell
266+
kubectl delete deployment hello-world
267+
```
266268

267269
## {{% heading "whatsnext" %}}
268270

269-
270271
<!--
271272
Learn more about
272273
[connecting applications with services](/docs/concepts/services-networking/connect-applications-service/).
273274
-->
274-
275-
了解更多关于[将应用程序与服务连接](/zh/docs/concepts/services-networking/connect-applications-service/)
276-
275+
进一步了解[将应用程序与服务连接](/zh/docs/concepts/services-networking/connect-applications-service/)
277276

0 commit comments

Comments
 (0)