高可用能力构建 本章节介绍如何在服务网格中使用本地限流 前提条件 1. 已开通云容器引擎,至少有一个云容器引擎集群实例。产品入口:云容器引擎。 2. 开通天翼云服务网格实例。 操作步骤 我们以bookinfo应用为例演示本地限流能力,首先在default命名空间部署bookinfo应用。 然后在default命名空间部署针对productpage服务的限流策略,token数量最大为5,每2秒重新填充5个token: apiVersion: istio.ctyun.cn/v1beta1 kind: LocalRateLimiter metadata: name: productpagelimit spec: workloadSelector: 匹配工作负载 labels: app: productpage context: SIDECARINBOUND statPrefix: httplocalratelimiter configs: name: productpage routeConfig: vhost: name: 'inboundhttp9080' rateLimitConfig: tokenBucket: maxTokens: 5 tokensPerFill: 5 fillInterval: 2s filterEnabled: runtimeKey: localratelimitenabled defaultValue: numerator: 100 denominator: HUNDRED filterEnforced: runtimeKey: localratelimitenforced defaultValue: numerator: 100 denominator: HUNDRED responseHeadersToAdd: appendAction: OVERWRITEIFEXISTSORADD header: key: xlocalratelimit value: 'true' 我们使用gostresstesting工具验证效果,如下图所示,结果状态码中有200和429(请求被限流);200的个数每2秒增加5个,符合我们设定的2秒重新填充5个token的设定;429状态码在持续增加。 单独请求productpage服务可以看到请求被限流的情况: