与认证类似ambassador 也是委托给三方的其他服务进行限速处理
基本的环境安装可以参考相关文档,主要还是qotm 服务
官方参考实现的简单限速服务
---apiVersion: v1kind: Servicemetadata: name: example-rate-limit annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: RateLimitService name: ratelimit service: "example-rate-limit:5000"spec: type: ClusterIP selector: app: example-rate-limit ports: - port: 5000 name: http-example-rate-limit targetPort: http-api---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: example-rate-limitspec: replicas: 1 strategy: type: RollingUpdate template: metadata: labels: app: example-rate-limit spec: containers: - name: example-rate-limit image: agervais/ambassador-ratelimit-service:1.0.0 imagePullPolicy: Always ports: - name: http-api containerPort: 5000 resources: limits: cpu: "0.1" memory: 100Mikubectl apply -f example-rate-limit.yaml
部署状态
服务配置
---apiVersion: v1kind: Servicemetadata:name: qotmannotations:getambassador.io/config: |---apiVersion: ambassador/v0kind: Mappingname: qotm_mappingprefix: /qotm/service: qotmrate_limits:- descriptor: A test caseheaders:- "x-ambassador-test-allow"spec:type: ClusterIPselector:app: qotmports:- port: 80name: http-qotmtargetPort: http-apikubectl apply -f service-config.yaml
测试服务
- 测试脚本
curl -v -H "x-ambassador-test-allow: probably" http://localhost:32190//qotm/quote/1
参考资料