如何为 istio 中的速率限制调试 QuotaSpecBinding?

How to debug QuotaSpecBinding for rate-limits in istio?

我正在尝试为启用了 istio 的服务启用速率限制。但它不起作用。如果我的配置正确,如何调试?

apiVersion: config.istio.io/v1alpha2
kind: memquota
metadata:
  name: handler
  namespace: istio-system
spec:
  quotas:
  - name: requestcount.quota.istio-system
    maxAmount: 5
    validDuration: 1s
    overrides:
    - dimensions:
        engine: myEngineValue
      maxAmount: 5
      validDuration: 1s
---
apiVersion: config.istio.io/v1alpha2
kind: quota
metadata:
  name: requestcount
  namespace: istio-system
spec:
  dimensions:
    source: request.headers["x-forwarded-for"] | "unknown"
    destination: destination.labels["app"] | destination.service | "unknown"
    destinationVersion: destination.labels["version"] | "unknown"
    engine: destination.labels["engine"] | "unknown"
---
apiVersion: config.istio.io/v1alpha2
kind: QuotaSpec
metadata:
  name: request-count
  namespace: istio-system
spec:
  rules:
  - quotas:
    - charge: 1
      quota: requestcount
---
apiVersion: config.istio.io/v1alpha2
kind: QuotaSpecBinding
metadata:
  name: request-count
  namespace: istio-system
spec:
  quotaSpecs:
  - name: request-count
    namespace: istio-system
  services:
  # - service: '*' ; I tried with this as well
  - name: my-service
    namespace: default
---
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
  name: quota
  namespace: istio-system
spec:
  actions:
  - handler: handler.memquota
    instances:
    - requestcount.quota

我也在 QuotaSpecBinding 中尝试使用 - service: '*';但运气不好。

如何确认我的配置是否正确? my-service 是我部署的 kubernetes 服务。 (这是否必须是 istio 的 VirtualService 才能使速率限制起作用?编辑:是的,它必须!

除了 VirtualService 部分,我遵循了 this doc

我感觉我在命名空间的某个地方做错了。

您必须为服务定义虚拟服务 my-service:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myservice
spec:
  hosts:
  - myservice
  http:
  - route:
    - destination:
        host: myservice

通过这种方式,您可以让 Istio 知道您所指的是您托管的服务。

在调试方面,我知道有一个名为Kiali that aims to leverage observability in Istio environments. I know that they have validations for some Istio and Kubernetes objects: Istio configuration browse的项目。