# Service Mesh

Service Mesh（服务网格）是一个用于保证服务间安全、快速、可靠通信的网络代理组件，是随着微服务和云原生应用兴起而诞生的基础设施层。它通常以轻量级网络代理的方式同应用部署在一起（比如sidecar方式，如下图所示）。Serivce Mesh可以看作是一个位于TCP/IP之上的网络模型，抽象了服务间可靠通信的机制。但与TCP不同，它是面向应用的，为应用提供了统一的可视化和控制。

![](/files/9px8yac0pJA1jrZ8D42Y)

为了保证服务间通信的可靠性，Service Mesh需要支持熔断机制、延迟感知的负载均衡、服务发现、重试等一些列的特性。比如Linkerd处理一个请求的流程包括

* 查找动态路由确定请求的服务
* 查找该服务的实例
* Linkerd跟响应延迟等因素选择最优的实例
* 将请求转发给最优实例，记录延迟和响应情况
* 如果请求失败或实例实效，则转发给其他实例重试（需要是幂等请求）
* 如果请求超时，则直接失败，避免给后端增加更多的负载
* 记录请求的度量和分布式跟踪情况

为什么Service Mesh是必要的

* 将服务治理与实际服务解耦，避免微服务化过程中对应用的侵入
* 加速传统应用转型微服务或云原生应用

Service Mesh并非一个全新的功能，而是将已存在于众多应用之中的相关功能分离出来，放到统一的组件来管理。特别是在微服务应用中，服务数量庞大，并且可能是基于不同的框架和语言构建，分离出来的Service Mesh组件更容易管理和协调它们。

常见的 Service Mesh 框架包括

* [Istio](/apps/istio.md)
* [Conduit](https://github.com/feiskyer/kubernetes-handbook/tree/549e0e3c9ba0175e64b2d4719b5a46e9016d532b/apps/conduit.md)
* [Linkerd](/apps/index/linkerd.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kubernetes.feisky.xyz/apps/index/service-mesh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
