服务网格 以透明的方式为服务到服务通信提供专用网络。Istio 旨在帮助开发人员和运维人员解决服务网格功能,例如动态服务发现、双向传输层安全协议 (TLS)、断路器、速率限制和追踪。Jaeger 与 Istio 结合使用,增强了分布式网络系统中云原生应用的监控和追踪。本文介绍如何开始使用 Jaeger 构建 Kubernetes 平台上的 Istio 服务网格。
启动 Kubernetes 集群
Minikube 允许您在本地机器上运行基于虚拟机(例如 KVM、VirtualBox 或 HyperKit)的单节点 Kubernetes 集群。安装 Minikube 并使用以下 shell 脚本运行它
#!/bin/bash
export MINIKUBE_PROFILE_NAME=istio-jaeger
minikube profile $MINIKUBE_PROFILE_NAME
minikube config set cpus 3
minikube config set memory 8192
# You need to replace appropriate VM driver on your local machine
minikube config set vm-driver hyperkit
minikube start
更多关于 Kubernetes 的信息
在上面的脚本中,将 --vm-driver=xxx 选项替换为您操作系统 (OS) 上合适的虚拟机驱动程序。
部署带有 Jaeger 的 Istio 服务网格
从 Istio 发布页面 下载适用于您操作系统的 Istio 安装文件。在 Istio 包目录中,您将在 install/ 中找到 Kubernetes 安装 YAML 文件,并在 sample/ 中找到示例应用程序。使用以下命令
$ curl -L https://git.io/getLatestIstio | sh -
$ cd istio-1.0.5
$ export PATH=$PWD/bin:$PATH
在 Kubernetes 集群上部署带有 Jaeger 的 Istio 的最简单方法是使用 自定义资源定义。使用以下命令安装 Istio,并在 Sidecar 之间启用双向 TLS 身份验证
$ kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml
$ kubectl apply -f install/kubernetes/istio-demo-auth.yaml
通过使用以下命令并查看输出,检查 Kubernetes 集群上 Istio 的所有 Pod 是否已正确部署并正在运行
$ kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
grafana-59b8896965-p2vgs 1/1 Running 0 3h
istio-citadel-856f994c58-tk8kq 1/1 Running 0 3h
istio-cleanup-secrets-mq54t 0/1 Completed 0 3h
istio-egressgateway-5649fcf57-n5ql5 1/1 Running 0 3h
istio-galley-7665f65c9c-wx8k7 1/1 Running 0 3h
istio-grafana-post-install-nh5rw 0/1 Completed 0 3h
istio-ingressgateway-6755b9bbf6-4lf8m 1/1 Running 0 3h
istio-pilot-698959c67b-d2zgm 2/2 Running 0 3h
istio-policy-6fcb6d655f-lfkm5 2/2 Running 0 3h
istio-security-post-install-st5xc 0/1 Completed 0 3h
istio-sidecar-injector-768c79f7bf-9rjgm 1/1 Running 0 3h
istio-telemetry-664d896cf5-wwcfw 2/2 Running 0 3h
istio-tracing-6b994895fd-h6s9h 1/1 Running 0 3h
prometheus-76b7745b64-hzm27 1/1 Running 0 3h
servicegraph-5c4485945b-mk22d 1/1 Running 1 3h
构建示例微服务应用
您可以使用 Bookinfo 应用来了解 Istio 的功能。Bookinfo 由四个微服务应用组成:productpage、details、reviews 和 ratings,它们独立部署在 Minikube 上。每个微服务都将通过 Istio 使用以下命令部署一个 Envoy Sidecar
// Enable sidecar injection automatically
$ kubectl label namespace default istio-injection=enabled
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
// Export the ingress IP, ports, and gateway URL
$ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
$ 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}')
$ export INGRESS_HOST=$(minikube ip)
$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
访问 Jaeger 仪表板
要查看每个 HTTP 请求的追踪信息,请在命令行运行以下命令以生成一些流量
$ while true; do
curl -s http://${GATEWAY_URL}/productpage > /dev/null
echo -n .;
sleep 0.2
done
如果您按如下方式设置端口转发,则可以通过 Web 浏览器使用 http://localhost:16686 访问 Jaeger 仪表板
kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 16686:16686 &
您可以通过选择 productpage 服务后单击“查找追踪”来浏览所有追踪。您的仪表板将类似于这样

您还可以查看有关每个追踪的更多详细信息,以深入研究性能问题或已用时间,只需单击某个追踪即可。

结论
分布式追踪平台使您能够了解从服务到服务针对单个入口/出口流量发生了什么。Istio 会自动将各个追踪信息发送到分布式追踪平台 Jaeger,即使您的现代应用程序根本没有意识到 Jaeger 的存在。最终,此功能可帮助开发人员和运维人员更轻松、更快速地大规模进行故障排除。
1 条评论