Istio 是一种与 Kubernetes 集成的服务网格,用于管理和控制微服务之间的通信。它为 Kubernetes 集群内运行的服务提供高级流量管理、安全功能和可观察性。


下面的代码演示了如何在 Kubernetes 集群上部署 Istio。它将指导你使用 Istioctl 命令行工具安装 Istio,该工具有助于管理 Istio 组件。

【代码清单】

# Step 1: Download the Istio installation package
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.18.0 sh -
# Step 2: Change to the Istio package directory
cd istio-1.18.0
# Step 3: Add the istioctl client to your path
export PATH=$PWD/bin:$PATH
# Step 4: Install Istio on your Kubernetes cluster
istioctl install --set profile=demo -y
# Step 5: Label the namespace where you want to deploy your application
kubectl label namespace default istio-injection=enabled
# Step 6: Deploy a sample application
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.

【执行结果】

✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Installation complete

Istio 增加了一个名为服务网格的抽象层,允许你管理微服务之间的流量。默认情况下,Kubernetes 会处理基本的联网,但 Istio 通过负载平衡、细粒度路由、断路和使用互TLS(mTLS)进行安全的服务间通信等功能对其进行了扩展。部署 Istio 时,它会在每个微服务旁边注入一个 Envoy 代理作为侧载容器。使用 istio-injection=enabled 标记命名空间,可为在该命名空间内创建的任何 pod 自动注入侧卡。这样就能在不修改服务本身的情况下,对网络策略、安全性和可观察性进行集中控制,从而更轻松地管理复杂的微服务环境。

【小知识】

通过 Istio 的可观察性工具,您可以监控和跟踪整个应用栈中的服务行为。这包括自动收集指标、日志和跟踪。该系统与 Prometheus、Grafana 和 Jaeger 等流行工具集成,可深入洞察服务性能和问题。