使用 Google Kubernetes Engine 快速开始
快速开始操作指南,使用 Google Cloud Deployment Manager,在 Google Kubernetes Engine(GKE)上安装和运行 Istio。
这个快速开始创建了一个新的 GKE zonal cluster,安装当前版本的 Istio 并部署 Bookinfo 样例应用。在 Kubernetes 安装 Istio 指南 的基础上,使用 Deployment Manager 为 Kubernetes Engine 提供一个自动的细化步骤。
前置条件
本样例需要一个有效的,并且打开了账单功能的 Google Cloud Platform 项目。如果你还没有 GCP 账户,你可以注册一个300美金的免费试用账户。
确认为你的项目打开了 Google Kubernetes Engine API(并能通过导航条中的 “APIs & Services” -> “Dashboard” 找到)。如果你没有看到 “API enabled”,那么你可能需要点击 “Enable this API” 按钮来开启 API。
你必须安装和配置
gcloud
command line tool 并安装kubectl
组件(gcloud components install kubectl
)。如果你不想在你的电脑上安装gcloud
客户端,你可以通过 Google Cloud Shell 使用gcloud
来完成同样的事情。你必须设置你的默认计算服务账户来包括以下内容:
roles/container.admin
(Kubernetes Engine Admin)Editor
(默认)
为了设置以上内容,如下图所示,在 Cloud Console 上导航到 IAM 章节,并找到你的形如 `projectNumber-compute@developer.gserviceaccount.com` 的默认 GCE/GKE 服务账号。服务账号默认应该仅是 Editor 角色。然后在这个账户的 Roles 下拉列表中,找到 Kubernetes Engine 组,并选择 Kubernetes Engine Admin 角色。你的账户将会变成多重身份。
然后添加 Kubernetes Engine Admin
角色:
安装
启动 Deployment Manager
一旦你的账户和项目启用,点击下面的链接,打开 Deployment Manager。
就像其他教程中的“如何访问已安装的功能”一样,我们也建议保留默认设置。工具会默认创建一个特殊设置的 GKE alpha cluster,然后安装 Istio 控制平面、 Bookinfo 样例应用、 Grafana 、 Prometheus 、 ServiceGraph 和 跟踪 。 接下来你可以了解一下怎样访问所有这些功能。脚本只在
default
的命名空间中启用 Istio 自动注入。点击 Deploy:
等 Istio 完全部署好。注意这会消耗5分钟左右。
引导 gcloud
部署完成后,在你安装好的 gcloud
的工作站里,完成以下事项:
为你刚刚创建的 cluster 引导
kubectl
,并确认 cluster 在运行中,并且 Istio 是启用状态。$ gcloud container clusters list NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS istio-cluster us-central1-a 1.9.7-gke.1 35.232.222.60 n1-standard-2 1.9.7-gke.1 4 RUNNING
这里,这个集群的名字是
istio-cluster
。接下来为这个集群获取授权
$ gcloud container clusters get-credentials istio-cluster --zone=us-central1-a
验证安装
验证 Istio 已经安装在它自己的命名空间中
$ kubectl get deployments,ing -n istio-system
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/grafana 1 1 1 1 4m
deploy/istio-citadel 1 1 1 1 4m
deploy/istio-egressgateway 1 1 1 1 4m
deploy/istio-ingress 1 1 1 1 4m
deploy/istio-ingressgateway 1 1 1 1 4m
deploy/istio-pilot 1 1 1 1 4m
deploy/istio-policy 1 1 1 1 4m
deploy/istio-sidecar-injector 1 1 1 1 4m
deploy/istio-statsd-prom-bridge 1 1 1 1 4m
deploy/istio-telemetry 1 1 1 1 4m
deploy/prometheus 1 1 1 1 4m
deploy/servicegraph 1 1 1 1 4m
现在确认 Bookinfo 样例应用也已经安装好:
$ kubectl get deployments,ing
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/details-v1 1 1 1 1 7m
deploy/productpage-v1 1 1 1 1 7m
deploy/ratings-v1 1 1 1 1 7m
deploy/reviews-v1 1 1 1 1 7m
deploy/reviews-v2 1 1 1 1 7m
deploy/reviews-v3 1 1 1 1 7m
现在获取 istio-ingress
的 IP:
$ kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.59.251.109 35.194.26.85 80:31380/TCP,443:31390/TCP,31400:31400/TCP 6m
记录下已经给 Bookinfo product page 指定好的 IP 和端口。(例子中是 35.194.26.85:80
)
你也可以在 Cloud Console 中的 Kubernetes Engine -> Workloads 章节找到这些:
访问 Bookinfo 样例
为 Bookinfo 的外网 IP 创建一个环境变量:
$ export GATEWAY_URL=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') $ echo $GATEWAY_URL
确认一下你可以访问 Bookinfo
http://${GATEWAY_URL}/productpage
:现在可以给它制造点流量:
$ for i in {1..100}; do curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage; done
验证已经安装的 Istio 插件
当你验证了 Istio 控制平面和样例应用正常工作后,尝试访问一下已经安装好的 Istio 插件。
如果你使用 Cloud Shell 而不是已经安装好的 gcloud
客户端,你可以使用 Web Preview 功能来进行端口转发和代理。比如,你要用 Cloud Shell 访问 Grafana,那你需要把 kubectl
的端口映射从 3000:3000 改成 8080:3000。你可以通过 Web Preview 代理的 8080 到 8084 这些端口,同时预览其他4个控制台。
Grafana
建立一个 Grafana 通道:
$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 &
然后访问
http://localhost:3000/dashboard/db/istio-dashboard
你应该可以看到一些你之前发送的请求的统计信息。
更多关于 Grafana 插件的细节,请点击关于 Grafana 插件。
Prometheus
Prometheus 是和 Grafana 一起安装好的。你可以使用控制台查看如下的 Istio 和应用指标:
$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &
在下面地址可以查看控制台:
http://localhost:9090/graph
更多关于 Prometheus 插件的细节,请点击关于 Prometheus 插件。
ServiceGraph
建立一个 ServiceGraph 通道:
$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=servicegraph -o jsonpath='{.items[0].metadata.name}') 8088:8088 &
你可以在下面的地址查看 Bookinfo 服务拓扑
http://localhost:8088/dotviz
更多关于 ServiceGraph 插件的细节,请点击关于 ServiceGraph 插件。
追踪
建立一个 Zipkin 通道:
$ kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 16686:16686 &
你就可以在 http://localhost:16686 查看之前的追踪统计信息
更多关于追踪的细节,请点击了解一下发生了什么。
卸载
在 https://console.cloud.google.com/deployments 找到 Cloud Console 的 Deployments 章节。
选择
deployment
并点击 Delete。Deployment Manager 将会删除所有已经部署的 GKE 组件。但是,有一些元素会被保留,比如
Ingress
和LoadBalancers
。你可以通过再次进入 cloud console 的 Network Services -> Load balancing 来删除这些组件。
See also
对 Google Kubernetes Engine(GKE)集群进行配置以便安装运行 Istio。
基于 GKE 的 Istio 多集群安装。
多 IBM Cloud Private 集群安装 Istio 示例。
安装支持多集群的 Istio。
这里讲述了 Istio 对 Kubernetes 中 Pod 和服务的要求。
对 Minikube 集群进行配置以便安装运行 Istio。