Resync tutorial page expose external IP address

This commit is contained in:
Qiming Teng
2020-10-29 14:21:02 +08:00
parent 2f5e9d5c1b
commit f1e5b34607
@@ -3,13 +3,10 @@ title: 公开外部 IP 地址以访问集群中应用程序
content_type: tutorial content_type: tutorial
weight: 10 weight: 10
--- ---
<!-- <!--
---
title: Exposing an External IP Address to Access an Application in a Cluster title: Exposing an External IP Address to Access an Application in a Cluster
content_type: tutorial content_type: tutorial
weight: 10 weight: 10
---
--> -->
<!-- overview --> <!-- overview -->
@@ -20,12 +17,8 @@ external IP address.
--> -->
此页面显示如何创建公开外部 IP 地址的 Kubernetes 服务对象。 此页面显示如何创建公开外部 IP 地址的 Kubernetes 服务对象。
## {{% heading "prerequisites" %}} ## {{% heading "prerequisites" %}}
<!-- <!--
* Install [kubectl](/docs/tasks/tools/install-kubectl/). * Install [kubectl](/docs/tasks/tools/install-kubectl/).
@@ -40,30 +33,23 @@ external IP address.
* 安装 [kubectl](/zh/docs/tasks/tools/install-kubectl/). * 安装 [kubectl](/zh/docs/tasks/tools/install-kubectl/).
* 使用 Google Kubernetes Engine 或 Amazon Web Services 等云供应商创建 Kubernetes 集。 * 使用 Google Kubernetes Engine 或 Amazon Web Services 等云供应商创建 Kubernetes 集
本教程创建了一个[外部负载均衡器](/zh/docs/tasks/access-application-cluster/create-external-load-balancer/)需要云供应商。 本教程创建了一个[外部负载均衡器](/zh/docs/tasks/access-application-cluster/create-external-load-balancer/)
需要云供应商。
* 配置 `kubectl` 与 Kubernetes API 服务器通信。有关说明,请参阅云供应商文档。 * 配置 `kubectl` 与 Kubernetes API 服务器通信。有关说明,请参阅云供应商文档。
## {{% heading "objectives" %}} ## {{% heading "objectives" %}}
<!-- <!--
* Run five instances of a Hello World application. * Run five instances of a Hello World application.
* Create a Service object that exposes an external IP address. * Create a Service object that exposes an external IP address.
* Use the Service object to access the running application. * Use the Service object to access the running application.
--> -->
* 运行 Hello World 应用程序的五个实例。 * 运行 Hello World 应用程序的五个实例。
* 创建一个公开外部 IP 地址的 Service 对象。 * 创建一个公开外部 IP 地址的 Service 对象。
* 使用 Service 对象访问正在运行的应用程序。 * 使用 Service 对象访问正在运行的应用程序。
<!-- lessoncontent --> <!-- lessoncontent -->
<!-- <!--
@@ -85,85 +71,98 @@ kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
<!-- <!--
The preceding command creates a The preceding command creates a
[Deployment](/docs/concepts/workloads/controllers/deployment/) {{< glossary_tooltip text="Deployment" term_id="deployment" >}}
object and an associated and an associated
[ReplicaSet](/docs/concepts/workloads/controllers/replicaset/) {{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}}.
object. The ReplicaSet has five The ReplicaSet has five
[Pods](/docs/concepts/workloads/pods/pod/), {{< glossary_tooltip text="Pods" term_id="pod" >}}
each of which runs the Hello World application. each of which runs the Hello World application.
--> -->
前面的命令创建一个 [Deployment](/zh/docs/concepts/workloads/controllers/deployment/) 前面的命令创建一个
对象和一个关联的 [ReplicaSet](/zh/docs/concepts/workloads/controllers/replicaset/)对象。 {{< glossary_tooltip text="Deployment" term_id="deployment" >}}
ReplicaSet 有五个 [Pod](/zh/docs/concepts/workloads/pods/pod/),每个都运行 Hello World 应用程序。 对象和一个关联的
{{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}} 对象。
ReplicaSet 有五个 {{< glossary_tooltip text="Pods" term_id="pod" >}}
每个都运行 Hello World 应用程序。
<!-- <!--
1. Display information about the Deployment: 1. Display information about the Deployment:
--> -->
2. 显示有关 Deployment 的信息: 2. 显示有关 Deployment 的信息:
```shell
kubectl get deployments hello-world kubectl get deployments hello-world
kubectl describe deployments hello-world kubectl describe deployments hello-world
```
<!-- <!--
1. Display information about your ReplicaSet objects: 1. Display information about your ReplicaSet objects:
--> -->
3. 显示有关 ReplicaSet 对象的信息: 3. 显示有关 ReplicaSet 对象的信息:
```shell
kubectl get replicasets kubectl get replicasets
kubectl describe replicasets kubectl describe replicasets
```
<!-- <!--
1. Create a Service object that exposes the deployment: 1. Create a Service object that exposes the deployment:
--> -->
4. 创建公开 deployment 的 Service 对象: 4. 创建公开 Deployment 的 Service 对象:
```shell
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
```
<!-- <!--
1. Display information about the Service: 1. Display information about the Service:
--> -->
5. 显示有关 Service 的信息: 5. 显示有关 Service 的信息:
```shell
kubectl get services my-service kubectl get services my-service
```
<!-- <!--
The output is similar to this: The output is similar to this:
--> -->
输出类似于: 输出类似于:
```
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service ClusterIP 10.3.245.137 104.198.205.71 8080/TCP 54s my-service ClusterIP 10.3.245.137 104.198.205.71 8080/TCP 54s
```
<!-- <!--
{{< note >}} {{< note >}}
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. 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.
{{< /note >}} {{< /note >}}
--> -->
注意:`type=LoadBalancer` 服务由外部云服务提供商提供支持,本例中不包含此部分,详细信息请参考[此页](/docs/concepts/services-networking/service/#loadbalancer) 提示:`type=LoadBalancer` 服务由外部云服务提供商提供支持,本例中不包含此部分,
详细信息请参考[此页](/docs/concepts/services-networking/service/#loadbalancer)
<!-- <!--
{{< note >}} {{< note >}}
If the external IP address is shown as \<pending\>, wait for a minute and enter the same command again. If the external IP address is shown as \<pending\>, wait for a minute and enter the same command again.
{{< /note >}} {{< /note >}}
--> -->
注意:如果外部 IP 地址显示为 \<pending\>,请等待一分钟再次输入相同的命令。 提示:如果外部 IP 地址显示为 \<pending\>,请等待一分钟再次输入相同的命令。
<!-- <!--
1. Display detailed information about the Service: 1. Display detailed information about the Service:
--> -->
6. 显示有关 Service 的详细信息: 6. 显示有关 Service 的详细信息:
```shell
kubectl describe services my-service kubectl describe services my-service
```
<!-- <!--
The output is similar to this: The output is similar to this:
--> -->
输出类似于: 输出类似于:
```
Name: my-service Name: my-service
Namespace: default Namespace: default
Labels: run=load-balancer-example Labels: run=load-balancer-example
@@ -177,7 +176,7 @@ If the external IP address is shown as \<pending\>, wait for a minute and enter
Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more... Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
Session Affinity: None Session Affinity: None
Events: <none> Events: <none>
```
<!-- <!--
Make a note of the external IP address (`LoadBalancer Ingress`) exposed by Make a note of the external IP address (`LoadBalancer Ingress`) exposed by
your service. In this example, the external IP address is 104.198.205.71. your service. In this example, the external IP address is 104.198.205.71.
@@ -188,7 +187,6 @@ If the external IP address is shown as \<pending\>, wait for a minute and enter
在本例中,外部 IP 地址是 104.198.205.71。还要注意 `Port` 和 `NodePort` 的值。 在本例中,外部 IP 地址是 104.198.205.71。还要注意 `Port` 和 `NodePort` 的值。
在本例中,`Port` 是 8080`NodePort` 是32377。 在本例中,`Port` 是 8080`NodePort` 是32377。
<!-- <!--
1. In the preceding output, you can see that the service has several endpoints: 1. In the preceding output, you can see that the service has several endpoints:
10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more. These are internal 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more. These are internal
@@ -200,27 +198,32 @@ If the external IP address is shown as \<pending\>, wait for a minute and enter
这些都是正在运行 Hello World 应用程序的 pod 的内部地址。 这些都是正在运行 Hello World 应用程序的 pod 的内部地址。
要验证这些是 pod 地址,请输入以下命令: 要验证这些是 pod 地址,请输入以下命令:
```shell
kubectl get pods --output=wide kubectl get pods --output=wide
```
<!-- <!--
The output is similar to this: The output is similar to this:
--> -->
输出类似于: 输出类似于:
```
NAME ... IP NODE NAME ... IP NODE
hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a
hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc
hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
```
<!-- <!--
1. Use the external IP address (`LoadBalancer Ingress`) to access the Hello 1. Use the external IP address (`LoadBalancer Ingress`) to access the Hello
World application: World application:
--> -->
8. 使用外部 IP 地址(`LoadBalancer Ingress`)访问 Hello World 应用程序: 8. 使用外部 IP 地址(`LoadBalancer Ingress`)访问 Hello World 应用程序:
```shell
curl http://<external-ip>:<port> curl http://<external-ip>:<port>
```
<!-- <!--
where `<external-ip>` is the external IP address (`LoadBalancer Ingress`) where `<external-ip>` is the external IP address (`LoadBalancer Ingress`)
@@ -238,20 +241,20 @@ If the external IP address is shown as \<pending\>, wait for a minute and enter
--> -->
成功请求的响应是一条问候消息: 成功请求的响应是一条问候消息:
```
Hello Kubernetes! Hello Kubernetes!
```
## {{% heading "cleanup" %}} ## {{% heading "cleanup" %}}
<!-- <!--
To delete the Service, enter this command: To delete the Service, enter this command:
--> -->
要删除服务,请输入以下命令: 要删除服务,请输入以下命令:
```shell
kubectl delete services my-service kubectl delete services my-service
```
<!-- <!--
To delete the Deployment, the ReplicaSet, and the Pods that are running To delete the Deployment, the ReplicaSet, and the Pods that are running
@@ -259,19 +262,15 @@ the Hello World application, enter this command:
--> -->
要删除正在运行 Hello World 应用程序的 DeploymentReplicaSet 和 Pod,请输入以下命令: 要删除正在运行 Hello World 应用程序的 DeploymentReplicaSet 和 Pod,请输入以下命令:
```shell
kubectl delete deployment hello-world kubectl delete deployment hello-world
```
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
<!-- <!--
Learn more about Learn more about
[connecting applications with services](/docs/concepts/services-networking/connect-applications-service/). [connecting applications with services](/docs/concepts/services-networking/connect-applications-service/).
--> -->
进一步了解[将应用程序与服务连接](/zh/docs/concepts/services-networking/connect-applications-service/)。
了解更多关于[将应用程序与服务连接](/zh/docs/concepts/services-networking/connect-applications-service/)。