diff --git a/content/zh/docs/tasks/access-application-cluster/ingress-minikube.md b/content/zh/docs/tasks/access-application-cluster/ingress-minikube.md index 01fba70e92..139123e8e2 100644 --- a/content/zh/docs/tasks/access-application-cluster/ingress-minikube.md +++ b/content/zh/docs/tasks/access-application-cluster/ingress-minikube.md @@ -2,11 +2,13 @@ title: 在 Minikube 环境中使用 NGINX Ingress 控制器配置 Ingress content_type: task weight: 100 +min-kubernetes-server-version: 1.19 --- @@ -25,31 +27,26 @@ This page shows you how to set up a simple Ingress which routes requests to Serv 本节为你展示如何配置一个简单的 Ingress,根据 HTTP URI 将服务请求路由到 服务 `web` 或 `web2`。 + ## {{% heading "prerequisites" %}} + {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} +如果你使用的是较早的 Kubernetes 版本,请切换到该版本的文档。 -## 创建一个 Minikube 集群 +### 创建一个 Minikube 集群 -1. 点击 **Launch Terminal** +使用 Katacoda +: {{< kat-button >}} - {{< kat-button >}} - - -2. (可选操作)如果你在本地安装了 Minikube,运行下面的命令: - - ```shell - minikube start - ``` +本地 +: 如果已经在本地[安装Minikube](/zh/docs/tasks/tools/#minikube), +请运行 `minikube start` 创建一个集群。 2. 检查验证 NGINX Ingress 控制器处于运行状态: - ```shell - kubectl get pods -n kube-system - ``` - - {{< note >}} - 这一操作可能需要近一分钟时间。 - {{< /note >}} + {{< tabs name="tab_with_md" >}} + {{% tab name="minikube v1.19 或更高版本" %}} +```shell +kubectl get pods -n ingress-nginx +``` + + {{< note >}}最多可能需要等待一分钟才能看到这些 Pod 运行正常。{{< /note >}} - 输出: + + 输出类似于: - ``` - NAME READY STATUS RESTARTS AGE - default-http-backend-59868b7dd6-xb8tq 1/1 Running 0 1m - kube-addon-manager-minikube 1/1 Running 0 3m - kube-dns-6dcb57bcc8-n4xd4 3/3 Running 0 2m - kubernetes-dashboard-5498ccf677-b8p5h 1/1 Running 0 2m - nginx-ingress-controller-5984b97644-rnkrg 1/1 Running 0 1m - storage-provisioner 1/1 Running 0 2m - ``` +``` +NAME READY STATUS RESTARTS AGE +ingress-nginx-admission-create-g9g49 0/1 Completed 0 11m +ingress-nginx-admission-patch-rqp78 0/1 Completed 1 11m +ingress-nginx-controller-59b45fb494-26npt 1/1 Running 0 11m +``` + {{% /tab %}} + {{% tab name="minikube v1.18.1 或更早版本" %}} +```shell +kubectl get pods -n kube-system +``` + + {{< note >}}最多可能需要等待一分钟才能看到这些 Pod 运行正常。{{< /note >}} + + + 输出类似于: + +``` +NAME READY STATUS RESTARTS AGE +default-http-backend-59868b7dd6-xb8tq 1/1 Running 0 1m +kube-addon-manager-minikube 1/1 Running 0 3m +kube-dns-6dcb57bcc8-n4xd4 3/3 Running 0 2m +kubernetes-dashboard-5498ccf677-b8p5h 1/1 Running 0 2m +nginx-ingress-controller-5984b97644-rnkrg 1/1 Running 0 1m +storage-provisioner 1/1 Running 0 2m +``` + + + 请确保可以在输出中看到一个名称以 `nginx-ingress-controller-` 为前缀的 Pod。 + {{% /tab %}} + {{< /tabs >}} + 输出: ``` @@ -120,7 +142,7 @@ This page shows you how to set up a simple Ingress which routes requests to Serv kubectl expose deployment web --type=NodePort --port=8080 ``` - + 输出: ``` @@ -136,8 +158,8 @@ This page shows you how to set up a simple Ingress which routes requests to Serv kubectl get service web ``` - - 输出: + + 输出类似于: ```shell NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE @@ -153,8 +175,8 @@ This page shows you how to set up a simple Ingress which routes requests to Serv minikube service web --url ``` - - 输出: + + 输出类似于: ```shell http://172.17.0.15:31637 @@ -169,8 +191,8 @@ This page shows you how to set up a simple Ingress which routes requests to Serv 输入节点和端口号(这里是`31637`),之后点击 **Display Port**。 {{< /note >}} - - 输出: + + 输出类似于: ```shell Hello, world! @@ -186,15 +208,15 @@ This page shows you how to set up a simple Ingress which routes requests to Serv 下一步是让自己能够通过 Ingress 资源来访问应用。 -## 创建一个 Ingress 资源 +## 创建一个 Ingress -下面是一个 Ingress 资源的配置文件,负责通过 `hello-world.info` 将服务请求 +下面是一个定义 Ingress 的配置文件,负责通过 `hello-world.info` 将请求 转发到你的服务。 1. 根据下面的 YAML 创建文件 `example-ingress.yaml`: @@ -202,15 +224,15 @@ The following file is an Ingress resource that sends traffic to your Service via {{< codenew file="service/networking/example-ingress.yaml" >}} -2. 通过运行下面的命令创建 Ingress 资源: +2. 通过运行下面的命令创建 Ingress 对象: ```shell kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml ``` - + 输出: ``` @@ -231,15 +253,19 @@ The following file is an Ingress resource that sends traffic to your Service via 此操作可能需要几分钟时间。 {{< /note >}} + + 接下来你将会在ADDRESS列中看到IPv4地址,例如: + ``` NAME CLASS HOSTS ADDRESS PORTS AGE example-ingress hello-world.info 172.17.0.15 80 38s ``` -4. 在 `/etc/hosts` 文件的末尾添加以下内容: +4. 在 `/etc/hosts` 文件的末尾添加以下内容(需要管理员访问权限): - 此设置使得来自 `hello-world.info` 的请求被发送到 Minikube。 + + 添加完成后,在浏览器中访问URL `hello-world.info`,请求将被发送到 Minikube。 - 输出: + + 你应该看到类似输出: ``` Hello, world! @@ -281,18 +310,19 @@ The following file is an Ingress resource that sends traffic to your Service via {{< /note >}} ## 创建第二个 Deployment -1. 使用下面的命令创建 v2 的 Deployment: +1. 使用下面的命令创建第二个 Deployment: ```shell kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0 ``` - + + 输出: ``` @@ -300,15 +330,15 @@ The following file is an Ingress resource that sends traffic to your Service via ``` -2. 将 Deployment 暴露出来: +2. 将第二个 Deployment 暴露出来: ```shell kubectl expose deployment web2 --port=8080 --type=NodePort ``` - + 输出: ``` @@ -316,13 +346,14 @@ The following file is an Ingress resource that sends traffic to your Service via ``` -## 编辑 Ingress +## 编辑现有的 Ingress {#edit-ingress} -1. 编辑现有的 `example-ingress.yaml`,添加以下行: +1. 编辑现有的 `example-ingress.yaml`,在文件最后添加以下行: ```yaml @@ -338,13 +369,13 @@ The following file is an Ingress resource that sends traffic to your Service via -2. 应用所作变更: +2. 应用变更: ```shell kubectl apply -f example-ingress.yaml ``` - + 输出: ``` @@ -364,8 +395,8 @@ The following file is an Ingress resource that sends traffic to your Service via curl hello-world.info ``` - - 输出: + + 输出类似于: ``` Hello, world! @@ -382,8 +413,8 @@ The following file is an Ingress resource that sends traffic to your Service via curl hello-world.info/v2 ``` - - 输出: + + 输出类似于: ``` Hello, world! @@ -392,7 +423,7 @@ The following file is an Ingress resource that sends traffic to your Service via ``` {{< note >}} 如果你在本地运行 Minikube 环境,你可以使用浏览器来访问 @@ -409,5 +440,4 @@ The following file is an Ingress resource that sends traffic to your Service via * 进一步了解 [Ingress](/zh/docs/concepts/services-networking/ingress/)。 * 进一步了解 [Ingress 控制器](/zh/docs/concepts/services-networking/ingress-controllers/) -* 进一步了解[服务](/zh/docs/concepts/services-networking/service/) - +* 进一步了解 [服务](/zh/docs/concepts/services-networking/service/)