From 3b21a7826ba4e9eb54474b30439a05e538822ba7 Mon Sep 17 00:00:00 2001 From: MJ-CJM <43091605+MJ-CJM@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:55:54 +0800 Subject: [PATCH] zh-trans:/docs/tutorials/hello-minikube.md (#14795) * . * . * . * . * . * . --- content/zh/docs/tutorials/hello-minikube.md | 524 ++++++++++++++++++++ content/zh/examples/minikube/Dockerfile | 4 + content/zh/examples/minikube/server.js | 9 + 3 files changed, 537 insertions(+) create mode 100644 content/zh/docs/tutorials/hello-minikube.md create mode 100644 content/zh/examples/minikube/Dockerfile create mode 100644 content/zh/examples/minikube/server.js diff --git a/content/zh/docs/tutorials/hello-minikube.md b/content/zh/docs/tutorials/hello-minikube.md new file mode 100644 index 0000000000..9464562358 --- /dev/null +++ b/content/zh/docs/tutorials/hello-minikube.md @@ -0,0 +1,524 @@ +--- +title: 你好 Minikube +content_template: templates/tutorial +weight: 5 +menu: + main: + title: "Get Started" + weight: 10 + post: > +
Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.
+card: + name: tutorials + weight: 10 +--- + + +{{% capture overview %}} + +本教程向您展示如何使用 [Minikube](/docs/getting-started-guides/minikube) 和 Katacoda 在 Kubernetes 上运行一个简单的 “Hello World” Node.js 应用程序。Katacoda 提供免费的浏览器内 Kubernetes 环境。 + +{{< note >}} + +如果您已在本地安装 [Minikube](/docs/tasks/tools/install-minikube/),也可以按照本教程操作。 + +{{< /note >}} + +{{% /capture %}} + +{{% capture objectives %}} + +* 将 "Hello World" 应用程序部署到 Minikube。 +* 运行应用程序。 +* 查看应用日志 + +{{% /capture %}} + +{{% capture prerequisites %}} + +本教程提供了从以下文件构建的容器镜像: + +{{< codenew language="js" file="minikube/server.js" >}} + +{{< codenew language="conf" file="minikube/Dockerfile" >}} + +有关 `docker build` 命令的更多信息,请参阅 [Docker 文档](https://docs.docker.com/engine/reference/commandline/build/)。 + +{{% /capture %}} + +{{% capture lessoncontent %}} + + +## 创建 Minikube 集群 + +1. 点击 **启动终端** + {{< kat-button >}} + + {{< note >}}如果您本地安装了 Minikube, 运行 `minikube start`.{{< /note >}} + +2. 在浏览器中打开 Kubernetes dashboard: + + ```shell + minikube dashboard + ``` + +3. 仅限 Katacoda 环境:在终端窗口的顶部,单击加号,然后单击 **选择要在主机 1 上查看的端口**。 + +4. 仅限 Katacoda 环境:输入“30000”,然后单击 **显示端口**。 + + +## 创建 Deployment + +Kubernetes [*Pod*](/docs/concepts/workloads/pods/pod/) 是由一个或多个容器为了管理和联网的目的而绑定在一起构成的组。本教程中的 Pod 只有一个容器。Kubernetes [*Deployment*](/docs/concepts/workloads/controllers/deployment/) 检查 Pod 的健康状况,并在 Pod 中的容器终止的情况下重新启动新的容器。Deployment 是管理 Pod 创建和扩展的推荐方法。 + +1. 使用 `kubectl create` 命令创建管理 Pod 的 Deployment。该 Pod 根据提供的 Docker 镜像运行 Container。 + + ```shell + kubectl create deployment hello-node --image=gcr.io/hello-minikube-zero-install/hello-node + ``` + +2. 查看 Deployment: + + ```shell + kubectl get deployments + ``` + + 输出: + + ```shell + NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE + hello-node 1 1 1 1 1m + ``` + +3. 查看 Pod: + + ```shell + kubectl get pods + ``` + 输出: + + ```shell + NAME READY STATUS RESTARTS AGE + hello-node-5f76cf6ccf-br9b5 1/1 Running 0 1m + ``` + +4. 查看集群事件: + + ```shell + kubectl get events + ``` + +5. 查看 `kubectl` 配置: + + ```shell + kubectl config view + ``` + {{< note >}}有关 kubectl 命令的更多信息,请参阅 [kubectl 概述](/docs/user-guide/kubectl-overview/)。{{< /note >}} + + +## 创建 Service + +默认情况下,Pod 只能通过 Kubernetes 集群中的内部 IP 地址访问。要使得 `hello-node` 容器可以从 Kubernetes 虚拟网络的外部访问,您必须将 Pod 暴露为 Kubernetes [*Service*](/docs/concepts/services-networking/service/)。 + +1. 使用 `kubectl expose` 命令将 Pod 暴露给公网: + + ```shell + kubectl expose deployment hello-node --type=LoadBalancer --port=8080 + ``` + + The `--type=LoadBalancer` flag indicates that you want to expose your Service + outside of the cluster. + +2. 查看您刚刚创建的服务: + + ```shell + kubectl get services + ``` + + 输出: + + ```shell + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + hello-node LoadBalancer 10.108.144.78