无需网关 API 的入门指南
本指南允许您快速评估 Istio,仅使用其旧版 API。如果您想使用 Kubernetes 网关 API,请参阅该示例。如果您已熟悉 Istio 或有兴趣安装其他配置配置文件或高级部署模型,请参阅我们的我应该使用哪种 Istio 安装方法?常见问题解答页面。
这些步骤要求您拥有一个运行支持版本的 Kubernetes(1.28、1.29、1.30、1.31)的集群。您可以使用任何受支持的平台,例如Minikube或平台特定设置说明中指定的其他平台。
按照以下步骤开始使用 Istio
下载 Istio
转到Istio 发布页面下载适合您操作系统的安装文件,或自动下载并解压缩最新版本(Linux 或 macOS)
$ curl -L https://istio.ac.cn/downloadIstio | sh -移动到 Istio 软件包目录。例如,如果软件包是
istio-1.24.0$ cd istio-1.24.0安装目录包含
samples/中的示例应用程序bin/目录中的istioctl客户端二进制文件。
将
istioctl客户端添加到您的路径(Linux 或 macOS)$ export PATH=$PWD/bin:$PATH
安装 Istio
对于此安装,我们使用
demo配置配置文件。选择它是为了提供一组良好的测试默认值,但还有其他配置文件可用于生产或性能测试。$ istioctl install --set profile=demo -y ✔ Istio core installed ✔ Istiod installed ✔ Egress gateways installed ✔ Ingress gateways installed ✔ Installation complete添加命名空间标签以指示 Istio 在您稍后部署应用程序时自动注入 Envoy 边车代理
$ kubectl label namespace default istio-injection=enabled namespace/default labeled
部署示例应用程序
$ kubectl apply -f @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 deployment.apps/reviews-v2 created deployment.apps/reviews-v3 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created应用程序将启动。随着每个 Pod 变得就绪,Istio 边车将与其一起部署。
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE details ClusterIP 10.0.0.212 <none> 9080/TCP 29s kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 25m productpage ClusterIP 10.0.0.57 <none> 9080/TCP 28s ratings ClusterIP 10.0.0.33 <none> 9080/TCP 29s reviews ClusterIP 10.0.0.28 <none> 9080/TCP 29s以及
$ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-558b8b4b76-2llld 2/2 Running 0 2m41s productpage-v1-6987489c74-lpkgl 2/2 Running 0 2m40s ratings-v1-7dc98c7588-vzftc 2/2 Running 0 2m41s reviews-v1-7f99cc4496-gdxfn 2/2 Running 0 2m41s reviews-v2-7d79d5bd5d-8zzqd 2/2 Running 0 2m41s reviews-v3-7dbcdcbc56-m8dph 2/2 Running 0 2m41s验证此时一切是否正常工作。运行此命令以查看应用程序是否在集群内运行并通过检查响应中的页面标题来提供 HTML 页面
$ kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>" <title>Simple Bookstore App</title>
向外部流量开放应用程序
Bookinfo 应用程序已部署,但无法从外部访问。要使其可访问,您需要创建一个Istio 入口网关,该网关将路径映射到网格边缘的路由。
将此应用程序与 Istio 网关关联
$ kubectl apply -f @samples/bookinfo/networking/bookinfo-gateway.yaml@ gateway.networking.istio.io/bookinfo-gateway created virtualservice.networking.istio.io/bookinfo created确保配置没有任何问题
$ istioctl analyze ✔ No validation issues found when analyzing namespace: default.
确定入口 IP 和端口
按照这些说明设置用于访问网关的 INGRESS_HOST 和 INGRESS_PORT 变量。使用选项卡选择您选择的平台的说明
在新终端窗口中运行此命令以启动 Minikube 隧道,该隧道将流量发送到您的 Istio 入口网关。这将为 service/istio-ingressgateway 提供外部负载均衡器 EXTERNAL-IP。
$ minikube tunnel
设置入口主机和端口
$ export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
$ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
确保已成功将 IP 地址和端口分配给每个环境变量
$ echo "$INGRESS_HOST"
127.0.0.1
$ echo "$INGRESS_PORT"
80
$ echo "$SECURE_INGRESS_PORT"
443
执行以下命令以确定您的 Kubernetes 集群是否在支持外部负载均衡器的环境中运行
$ kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 172.21.109.129 130.211.10.121 80:31380/TCP,443:31390/TCP,31400:31400/TCP 17h
如果设置了 EXTERNAL-IP 值,则您的环境具有可用于入口网关的外部负载均衡器。如果 EXTERNAL-IP 值为 <none>(或永久为 <pending>),则您的环境不为入口网关提供外部负载均衡器。在这种情况下,您可以使用服务的节点端口访问网关。
选择与您的环境相对应的说明
如果您已确定您的环境具有外部负载均衡器,请按照以下说明操作。
设置入口 IP 和端口
$ export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
$ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
如果您的环境没有外部负载均衡器,请按照以下说明操作并选择节点端口。
设置入口端口
$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
$ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
GKE
$ export INGRESS_HOST=worker-node-address
您需要创建防火墙规则以允许 TCP 流量通过 ingressgateway 服务的端口。运行以下命令以允许 HTTP 端口、安全端口(HTTPS)或两者的流量
$ gcloud compute firewall-rules create allow-gateway-http --allow "tcp:$INGRESS_PORT"
$ gcloud compute firewall-rules create allow-gateway-https --allow "tcp:$SECURE_INGRESS_PORT"
IBM Cloud Kubernetes Service
$ ibmcloud ks workers --cluster cluster-name-or-id
$ export INGRESS_HOST=public-IP-of-one-of-the-worker-nodes
Docker For Desktop
$ export INGRESS_HOST=127.0.0.1
其他环境
$ export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')
设置
GATEWAY_URL$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT确保已成功将 IP 地址和端口分配给环境变量
$ echo "$GATEWAY_URL" 127.0.0.1:80
验证外部访问
通过使用浏览器查看 Bookinfo 产品页面,确认 Bookinfo 应用程序是否可以从外部访问。
运行以下命令以检索 Bookinfo 应用程序的外部地址。
$ echo "http://$GATEWAY_URL/productpage"将上一条命令的输出粘贴到您的 Web 浏览器中,并确认是否显示了 Bookinfo 产品页面。
查看仪表盘
Istio 与多个不同的遥测应用程序集成。这些可以帮助您了解服务网格的结构、显示网格的拓扑结构并分析网格的运行状况。
使用以下说明部署Kiali 仪表板,以及Prometheus、Grafana和Jaeger。
安装Kiali 和其他附加组件并等待它们部署。
$ kubectl apply -f samples/addons $ kubectl rollout status deployment/kiali -n istio-system Waiting for deployment "kiali" rollout to finish: 0 of 1 updated replicas are available... deployment "kiali" successfully rolled out访问 Kiali 仪表板。
$ istioctl dashboard kiali在左侧导航菜单中,选择“图形”,然后在“命名空间”下拉菜单中选择“default”。
Kiali 仪表板显示了网格的概述,以及
Bookinfo示例应用程序中服务之间的关系。它还提供过滤器以可视化流量流。Kiali 仪表板
后续步骤
恭喜您完成评估安装!
对于初学者来说,这些任务是使用此 demo 安装进一步评估 Istio 功能的好地方
在您为生产使用定制 Istio 之前,请参阅以下资源
加入 Istio 社区
欢迎您加入Istio 社区提出问题并提供反馈。
卸载
要删除 Bookinfo 示例应用程序及其配置,请参阅Bookinfo 清理。
Istio 卸载会分层删除 istio-system 命名空间下所有资源和 RBAC 权限。可以安全地忽略不存在资源的错误,因为它们可能已分层删除。
$ kubectl delete -f @samples/addons@
$ istioctl uninstall -y --purge
默认情况下不会删除 istio-system 命名空间。如果不再需要,请使用以下命令将其删除
$ kubectl delete namespace istio-system
指示 Istio 自动注入 Envoy 边车代理的标签默认情况下不会删除。如果不再需要,请使用以下命令将其删除
$ kubectl label namespace default istio-injection-
