From 8cc207566dadf15cdb7106c5a228ffef7133e7bc Mon Sep 17 00:00:00 2001 From: lIuDuI <1693291525@qq.com> Date: Sun, 10 Mar 2019 12:53:27 +0800 Subject: [PATCH] ZH-trans: add expose-external-ip-address.md (#12955) * ZH-trans: add expose-external-ip-address.md * Update expose-external-ip-address.md * Update expose-external-ip-address.md * Update expose-external-ip-address.md * Update expose-external-ip-address.md * Update expose-external-ip-address.md --- .../expose-external-ip-address.md | 257 ++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 content/zh/docs/tutorials/stateless-application/expose-external-ip-address.md diff --git a/content/zh/docs/tutorials/stateless-application/expose-external-ip-address.md b/content/zh/docs/tutorials/stateless-application/expose-external-ip-address.md new file mode 100644 index 0000000000..b22d2a365a --- /dev/null +++ b/content/zh/docs/tutorials/stateless-application/expose-external-ip-address.md @@ -0,0 +1,257 @@ +--- +title: 公开外部 IP 地址以访问集群中应用程序 +content_template: templates/tutorial +weight: 10 +--- + + + +{{% capture overview %}} + + +此页面显示如何创建公开外部 IP 地址的 Kubernetes 服务对象。 + +{{% /capture %}} + + +{{% capture prerequisites %}} + + + + * 安装 [kubectl](/docs/tasks/tools/install-kubectl/). + + * 使用 Google Kubernetes Engine 或 Amazon Web Services 等云供应商创建 Kubernetes 群集。 + 本教程创建了一个[外部负载均衡器](/docs/tasks/access-application-cluster/create-external-load-balancer/),需要云供应商。 + + * 配置 `kubectl` 与 Kubernetes API 服务器通信。有关说明,请参阅云供应商文档。 + +{{% /capture %}} + + +{{% capture objectives %}} + + + +* 运行 Hello World 应用程序的五个实例。 +* 创建一个公开外部 IP 地址的 Service 对象。 +* 使用 Service 对象访问正在运行的应用程序。 + +{{% /capture %}} + + +{{% capture lessoncontent %}} + + + +## 为一个在五个 pod 中运行的应用程序创建服务 + + +1. 在集群中运行 Hello World 应用程序: + + kubectl run hello-world --replicas=5 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080 + + + 前面的命令创建一个 [Deployment](/docs/concepts/workloads/controllers/deployment/) + 对象和一个关联的 [ReplicaSet](/docs/concepts/workloads/controllers/replicaset/)对象。 + ReplicaSet 有五个 [Pod](/docs/concepts/workloads/pods/pod/),每个都运行 Hello World 应用程序。 + + +2. 显示有关 Deployment 的信息: + + kubectl get deployments hello-world + kubectl describe deployments hello-world + + +3. 显示有关 ReplicaSet 对象的信息: + + kubectl get replicasets + kubectl describe replicasets + + +4. 创建公开 deployment 的 Service 对象: + + kubectl expose deployment hello-world --type=LoadBalancer --name=my-service + + +5. 显示有关 Service 的信息: + + kubectl get services my-service + + + 输出类似于: + + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + my-service ClusterIP 10.3.245.137 104.198.205.71 8080/TCP 54s + + + 注意:如果外部 IP 地址显示为 \,请等待一分钟再次输入相同的命令。 + + +6. 显示有关 Service 的详细信息: + + kubectl describe services my-service + + + 输出类似于: + + Name: my-service + Namespace: default + Labels: run=load-balancer-example + Annotations: + Selector: run=load-balancer-example + Type: LoadBalancer + IP: 10.3.245.137 + LoadBalancer Ingress: 104.198.205.71 + Port: 8080/TCP + NodePort: 32377/TCP + Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more... + Session Affinity: None + Events: + + + 记下服务公开的外部 IP 地址(`LoadBalancer Ingress`)。 + 在本例中,外部 IP 地址是 104.198.205.71。还要注意 `Port` 和 `NodePort` 的值。 + 在本例中,`Port` 是 8080,`NodePort` 是32377。 + + + +7. 在前面的输出中,您可以看到服务有几个端点: + 10.0.0.6:8080、10.0.1.6:8080、10.0.1.7:8080 和另外两个, + 这些都是正在运行 Hello World 应用程序的 pod 的内部地址。 + 要验证这些是 pod 地址,请输入以下命令: + + kubectl get pods --output=wide + + + 输出类似于: + + NAME ... IP NODE + 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-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-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc + + +8. 使用外部 IP 地址(`LoadBalancer Ingress`)访问 Hello World 应用程序: + + curl http://: + + + 其中 `` 是您的服务的外部 IP 地址(`LoadBalancer Ingress`), + `` 是您的服务描述中的 `port` 的值。 + 如果您正在使用 minikube,输入 `minikube service my-service` 将在浏览器中自动打开 Hello World 应用程序。 + + + 成功请求的响应是一条问候消息: + + Hello Kubernetes! + +{{% /capture %}} + + +{{% capture cleanup %}} + + +要删除服务,请输入以下命令: + + kubectl delete services my-service + + +要删除正在运行 Hello World 应用程序的 Deployment,ReplicaSet 和 Pod,请输入以下命令: + + kubectl delete deployment hello-world + +{{% /capture %}} + + +{{% capture whatsnext %}} + + + +了解更多关于[将应用程序与服务连接](/docs/concepts/services-networking/connect-applications-service/)。 + +{{% /capture %}}