zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Linkerd Service Mesh 服务配置文件规范

2023-04-18 14:43:44 时间

服务配置文件Linkerd 提供有关服务的附加信息。以下是可以使用服务配置文件完成的所有操作的参考。

系列

中文手册(https://linkerd.hacker-linner.com)

Spec(规范)

服务配置文件规范必须包含以下顶级字段:

route 对象的列表

Route(路由)

route 对象必须包含以下字段:

这条 route 的名称,因为它将出现在 route 标签中

Request Match(请求匹配)

请求匹配对象必须恰好包含以下字段之一:

匹配请求路径的正则表达式

Request Match 使用示例

最简单的条件是路径正则表达式:

pathRegex: '/authors/d+'

这是检查请求方法的条件:

method: POST

如果设置了多个条件字段,则必须满足所有条件。这等效于使用 all 条件:

all:
- pathRegex: '/authors/d+'
- method: POST

可以使用 allanynot 组合条件:

any:
- all:
  - method: POST
  - pathRegex: '/authors/d+'
- all:
  - not:
      method: DELETE
  - pathRegex: /info.txt

Response Class(响应类)

response class 对象必须包含以下字段:

一个 response match 对象,它定义一个 response 是否匹配这个 response class

Response Match(响应匹配)

response match 对象必须恰好包含以下字段之一:

用于匹配响应状态代码的 status range 对象

Response Match 条件可以以类似于上面显示的 Request Match 使用示例 的方式组合

Status Range(状态范围)

status range 对象必须包含以下至少一个字段。只指定 minmax 中的一个将只匹配一个状态码。

状态码必须大于或等于此值

Retry Budget(重试预算)

retry budget 指定应发送到此服务的最大重试总次数原始请求量比率

重试请求与原始请求的最大比率

实战

  • 设置服务配置文件
    • https://linkerd.hacker-linner.com/2.11/tasks/setting-up-service-profiles/
  • 完整的 demo 演练
    • https://linkerd.hacker-linner.com/2.11/tasks/books/#service-profiles/