Istio从入门到精通—— Istio架构

Istio 架构

https://istio.io/latest/docs/ops/deployment/architecture/

Istio 服务网格在逻辑上分为数据平面控制平面

    • The data plane is composed of a set of intelligent proxies (Envoy) deployed as sidecars. These proxies mediate and control all network communication between microservices. They also collect and report telemetry on all mesh traffic.

(数据平面由一组作为 sidecars 部署的智能代理(Envoy)组成。这些代理协调和控制微服务之间的所有网络通信。他们还收集和报告所有网格传输遥测。)

    • The control plane manages and configures the proxies to route traffic.

(控制平面管理和配置代理以路由传输)

下图显示了组成每个平面的不同部件:

一、Envoy

   Istio uses an extended version of the Envoy proxy. Envoy is a high-performance proxy developed in C++ to mediate all inbound and outbound traffic for all services in the service mesh. Envoy proxies are the only Istio components that interact with data plane traffic.

(Istio 使用了 Envoy 代理的扩展版本。Envoy 是一个用 C++ 开发的高性能代理,用于协调服务网格中所有服务的所有入站和出站流量。Envoy 代理是唯一与数据平面通信交互的 Istio 组件。)

Envoy proxies are deployed as sidecars to services, logically augmenting the services with Envoy’s many built-in features, for example:

(Envoy代理被部署为服务的 sidecars,从逻辑上增加了 Envoy 的许多内置功能的服务,例如):

    • Dynamic service discovery (动态服务发现)
    • Load balancing (负载平衡)
    • TLS termination (TLS 终止)
    • HTTP/2 and gRPC proxies (HTTP/2和 gRPC 代理)
    • Circuit breakers (断路器)
    • Health checks (健康检查)
    • Staged rollouts with %-based traffic split (分阶段推出基于 % 的流量分割)
    • Fault injection 故障注入)
    • Rich metrics  丰富的指标)

This sidecar deployment allows Istio to enforce policy decisions and extract rich telemetry which can be sent to monitoring systems to provide information about the behavior of the entire mesh.

(这种 sidecar 部署使 Istio 能够强制执行政策决定,并提取丰富的遥测数据,这些数据可以发送到监控系统,以提供关于整个网格行为的信息。)

  The sidecar proxy model also allows you to add Istio capabilities to an existing deployment without requiring you to rearchitect or rewrite code.

(Sidecar 代理模型还允许您向现有部署添加 Istio 功能,而无需重新架构或重写代码。)

  Some of the Istio features and tasks enabled by Envoy proxies include:

(Envoy 代理推动的 Istio 的一些特点和任务包括):

    • Traffic control features: enforce fine-grained traffic control with rich routing rules for HTTP, gRPC, WebSocket, and TCP traffic.

      流量控制特性: 对 HTTP、gRPC、WebSocket和TCP流量使用丰富的路由规则实施细粒度流量控制。

    • Network resiliency features: setup retries, failovers, circuit breakers, and fault injection.

      网络弹性特性: 安装重试、故障转移、断路器和故障注入。

    • Security and authentication features: enforce security policies and enforce access control and rate limiting defined through the configuration API.

      安全和身份验证特性: 强制执行安全策略,并强制通过配置 API 定义的访问控制和速率限制。

    • Pluggable extensions model based on WebAssembly that allows for custom policy enforcement and telemetry generation for mesh traffic.

      基于 WebAssembly 的可插拔扩展模型,支持自定义策略实施和网格通信的遥测生成。

二、Istiod

  Istiod provides service discovery, configuration and certificate management.

(Istiod 提供服务发现、配置和证书管理。)

  Istiod converts high level routing rules that control traffic behavior into Envoy-specific configurations, and propagates them to the sidecars at runtime. Pilot abstracts platform-specific service discovery mechanisms and synthesizes them into a standard format that any sidecar conforming with the Envoy API can consume.

(Istiod 将控制流量行为的高级路由规则转换为特使特有的配置,并在运行时将其传播到 sirdecars。示范项目对特定于平台的服务发现机制进行了抽象,并将其综合成符合特使 API 的任何边车都可以使用的标准格式。)

  Istio can support discovery for multiple environments such as Kubernetes or VMs.

(Istio 可以支持针对多个环境(如 Kubernetes 或 VM)的发现。)

  You can use Istio’s Traffic Management API to instruct Istiod to refine the Envoy configuration to exercise more granular control over the traffic in your service mesh.

(您可以使用 Istio 的流量管理 API 来指示 Istiod 改进 Envoy 配置,以便对服务网格中的流量进行更细粒度的控制。)

  Istiod security enables strong service-to-service and end-user authentication with built-in identity and credential management. You can use Istio to upgrade unencrypted traffic in the service mesh. Using Istio, operators can enforce policies based on service identity rather than on relatively unstable layer 3 or layer 4 network identifiers. Additionally, you can use Istio’s authorization feature to control who can access your services.

(Istiod 安全性支持内置身份和凭证管理的强大服务对服务和终端用户身份验证。您可以使用 Istio 升级服务网格中的未加密流量。使用 Istio,运营商可以根据服务标识而不是相对不稳定的第3层或第4层网络标识来执行策略。此外,您可以使用 Istio 的授权特性来控制谁可以访问您的服务。)

  Istiod acts as a Certificate Authority (CA) and generates certificates to allow secure mTLS communication in the data plane.

(Istiod 充当证书颁发机构(CA) ,并生成证书以允许数据平面中的安全 mTLS 通信。)

三、Istio 的架构及原理

  观察 frontend 对 forecast 进行一次访问时,在 Istio 内部都发生了什么,以及 Istio 的各个组件是怎样参与其中的,分别做了哪些事情。

  虽然从时序来讲,控制面的配置在前,数据面的执行在后,但为了便于理解,在下面介绍这些动作时以数据面上的数据流为入口,介绍数据面的功能,然后讲解涉及的控制面如何提供对应的支持,进而理解控制面上组件的对应功能。

  1、自动注入:指在创建应用程序时,自动注入 Sidecar 代理和 Init 容器。在 Kubernetes 场景中创建 Pod 时,Kube-apiserver 调用 Istio 的 Sidecar-injector 服务,自动修改应用程序的描述信息并注入 Sidecar 代理和 Init 容器。在真正运行 Pod 时,首先运行 Init 容器,设置流量拦截规则,然后同时运行应用容器和 Sidecar 容器。在用户无感知的情况下,Sidecar 容器中的 Envoy 程序伴随着应用程序运行,对进出应用程序的流量进行透明的管理。

  2、流量拦截:Istio 默认通过注入 Init 容器进行 Iptables 规则的设置,拦截进入容器的 Inbound 流量和从应用程序发出的 Outbound 流量。由于 Init 容器需要 NET_ADMIN 和 NET_RAW 权限执行网络设置,所以 Istio 还提供了 Istio CNI 插件,取代 Init 容器进行流量拦截规则的设置。Istio CNI 插件识别用户的应用程序 Pod 和需要流量重定向的 Sidecar,并在 Kubernetes Pod 生命周期的网络设置阶段进行设置,从而消除用户在启用 Istio 的集群中对 Pod 额外的权限要求。当有流量来时,Sidecar 基于配置的 iptables 规则拦截业务容器的 Inbound 流量和 Outbound 流量。应用程序完全感知不到 Sidecar 的存在,仍然以原本的方式进行访问。forecast 发送的流量就会被 frontend 侧的 Sidecar 拦截,而当流量到达 forecast 时,Inbound 流量被 forecast 侧的 Sidecar 拦截。

  3、服务发现:服务发起方的 Envoy 调用 Istio 的服务发现接口获取目标服务的实例列表。frontend 侧的 Envoy 通过 Pilot 的服务发现接口得到 forecast 各个实例的地址,为负载均衡做好准备。

  4、负载均衡:服务发起方的 Envoy 根据配置的负载均衡策略选择服务实例,并将请求分发到对应的目标服务实例上。frontend 侧的 Envoy 从 Istiod 中获取 forecast 的负载均衡配置并执行负载均衡操作。

  5、流量治理:Envoy 从 Istiod 中获取配置的流量治理规则,在拦截到 Inbound 流量和 Outbound 流量时执行治理逻辑。frontend 侧的 Envoy 从 Istiod 中获取流量治理规则,并根据灰度策略将不同特征的流量分发到 forecast 的 v1 和 v2 版本。当然,这只是 Istio 流量治理的一个简单场景,更丰富的流量治理能力参考目标服务的代理,比如对 forecast 的限流、认证和授权等。

  6、访问安全:在服务间访问时,Envoy 可以进行双向认证和通道加密,并基于授权策略的配置对请求进行鉴权。上图是默认启用服务间的双向认证,在 frontend 和 forecast 侧的 Envoy 上自动加载证书和密钥来实现双向认证。其中的证书和密钥的管理比较复杂,由 Citadel 和 Istio-Agent 协作完成。

  7、服务监控:在服务间通信时,通信双方的 Envoy 根据请求的信息进行监控指标的统计、访问日志的收集和分布式调用链的埋点等。Istio 通过标准的可观测性接口对接各种不同的可观测性后端,接收相关的可观测性数据。frontend 对 forecast 的访问监控指标、访问日志和调用链都可以通过这种方式收集到对应的监控后端。

  8、策略执行:Envoy 原生支持访问限流。可以部署限流服务,通过限流规则控制 frontend 到 forecast 的访问速率。由于种种原因,截至 Isito 1.16,Istio 暂时还没有标准的限流 API 帮助用户配置限流策略,在限流策略的配置方面,还只能通过 EnvoyFilter 开放的 Envoy 的限流能力。

  9、访问入口:在服务网格的入口处有一个 Envoy 扮演入口网关 Ingress-gateway 的角色。外部服务通过网关访问入口服务 frontend,对 frontend 的负载均衡和一些流量治理策略都在这个网关上执行。

  10、外部服务:与入口网关 Ingress-gateway 类似,出口网关 Egress-gateway 统一接收和管理服务网格访问外部的流量。forecast 通过出口网关访问外部服务,还可以对外部访问的流量进行管理。

  总结在以上过程中涉及的动作和动作主体,对其中的每个过程都抽象成一句话:服务调用双方的服务网格数据面代理 Envoy 拦截流量,并根据 Istiod 的相关配置执行相应的治理动作,这也是 Istio 的数据面和控制面的基本配合方式。 

posted @ 2023-11-20 14:48  左扬  阅读(117)  评论(0编辑  收藏  举报
levels of contents