--- title: 使用 Kubernetes 运行 Bookinfo overview: 在 Kubernetes 中部署使用 ratings 微服务的 Bookinfo 应用。 weight: 30 owner: istio/wg-docs-maintainers test: no --- {{< boilerplate work-in-progress >}} 该模块显示了一个应用程序,它由四种以不同编程语言编写的微服务组成: `productpage`、`details`、`ratings` 和 `reviews`。我们将组成的应用程序称为 `Bookinfo`,您可以在 [Bookinfo 示例](/zh/docs/examples/bookinfo)页面中了解更多信息。 `reviews` 微服务具有三个版本:`v1`、`v2`、`v3`,而 [Bookinfo 示例](/zh/docs/examples/bookinfo)展示的是该应用的最终版本。 在此模块中,应用程序仅使用 `reviews` 微服务的 `v1` 版本。接下来的模块通过多个版本的 `reviews` 微服务增强了应用程序。 ## 部署应用程序及测试 Pod {#deploy-the-application-and-a-testing-pod} 1. 设置环境变量 `MYHOST` 的值为应用程序的 URL: {{< text bash >}} $ export MYHOST=$(kubectl config view -o jsonpath={.contexts..namespace}).bookinfo.com {{< /text >}} 1. 浏览 [`bookinfo.yaml`]({{< github_blob >}}/samples/bookinfo/platform/kube/bookinfo.yaml)。 这是该应用的 Kubernetes 部署规范。注意 Service 和 Deployment。 1. 部署应用到 Kubernetes 集群: {{< text bash >}} $ kubectl apply -l version!=v2,version!=v3 -f {{< github_file >}}/samples/bookinfo/platform/kube/bookinfo.yaml service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created {{< /text >}} 1. 检查 Pod 的状态: {{< text bash >}} $ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-6d86fd9949-q8rrf 1/1 Running 0 10s productpage-v1-c9965499-tjdjx 1/1 Running 0 8s ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 9s reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 9s {{< /text >}} 1. 四个服务达到 `Running` 状态后,就可以扩展 deployment。要使每个微服务的每个版本在三个 Pod 中运行,请执行以下命令: {{< text bash >}} $ kubectl scale deployments --all --replicas 3 deployment.apps/details-v1 scaled deployment.apps/productpage-v1 scaled deployment.apps/ratings-v1 scaled deployment.apps/reviews-v1 scaled {{< /text >}} 1. 检查 Pod 的状态,可以看到每个微服务都有三个 Pod: {{< text bash >}} $ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-6d86fd9949-fr59p 1/1 Running 0 50s details-v1-6d86fd9949-mksv7 1/1 Running 0 50s details-v1-6d86fd9949-q8rrf 1/1 Running 0 1m productpage-v1-c9965499-hwhcn 1/1 Running 0 50s productpage-v1-c9965499-nccwq 1/1 Running 0 50s productpage-v1-c9965499-tjdjx 1/1 Running 0 1m ratings-v1-7bf577cb77-cbdsg 1/1 Running 0 50s ratings-v1-7bf577cb77-cz6jm 1/1 Running 0 50s ratings-v1-7bf577cb77-pq9kg 1/1 Running 0 1m reviews-v1-77c65dc5c6-5wt8g 1/1 Running 0 49s reviews-v1-77c65dc5c6-kjvxs 1/1 Running 0 1m reviews-v1-77c65dc5c6-r55tl 1/1 Running 0 49s {{< /text >}} 1. 在服务达到 `Running` 状态后,部署一个测试 Pod:[curl]({{< github_tree >}}/samples/curl)。 此 Pod 用来向您的微服务发送请求: {{< text bash >}} $ kubectl apply -f {{< github_file >}}/samples/curl/curl.yaml {{< /text >}} 1. 从测试 Pod 中用 curl 命令发送请求给 Bookinfo 应用,以确认该应用运行正常: {{< text bash >}} $ kubectl exec $(kubectl get pod -l app=curl -o jsonpath='{.items[0].metadata.name}') -c curl -- curl -sS productpage:9080/productpage | grep -o "