seninel部署
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Sentinel Envoy RLS - Kubernetes sample
  2. This sample will illustrate how to use Sentinel RLS token server with Envoy in Kubernetes clusters.
  3. ## Build the Docker image
  4. We could use the pre-built Docker image: `registry.cn-hangzhou.aliyuncs.com/sentinel-docker-repo/sentinel-envoy-rls-server:latest`
  5. We can also manually build the Docker image in the `sentinel-cluster-server-envoy-rls` directory:
  6. ```bash
  7. docker build -t "sentinel/sentinel-envoy-rls-server:latest" -f ./Dockerfile .
  8. ```
  9. ## Deploy Sentinel RLS token server
  10. Next we could deploy the Sentinel RLS token server in the K8S cluster.
  11. We've provided a deployment template for Sentinel RLS token server in `sentinel-rls.yml`.
  12. It includes:
  13. - A `ConfigMap` that contains the cluster flow control rule for Envoy global rate limiting.
  14. This will be mounted as a file in the target `Deployment`, so that the Sentinel RLS token server
  15. could load the rules dynamically as soon as the rule in the `ConfigMap` has been updated.
  16. - A `Deployment` for Sentinel RLS token server. It will mount the `ConfigMap` as a volume
  17. for dynamic rule configuration.
  18. - A `Service` that exports the Sentinel command port (8719) and the RLS gRPC port (by default 10245)
  19. on a cluster-internal IP so that the Envoy pods could communicate with the RLS server.
  20. The sample rate limiting rule in the `sentinel-rule-cm`:
  21. ```yaml
  22. domain: foo
  23. descriptors:
  24. # For requests to the "service_httpbin" cluster, limit the max QPS to 1
  25. - resources:
  26. - key: "destination_cluster"
  27. value: "service_httpbin"
  28. count: 1
  29. ```
  30. You may enable the access log in the Sentinel RLS token server (output to console)
  31. via the `SENTINEL_RLS_ACCESS_LOG` env:
  32. ```yaml
  33. env:
  34. - name: SENTINEL_RLS_ACCESS_LOG
  35. value: "on"
  36. ```
  37. You may also append JVM opts via the `JAVA_OPTS` env.
  38. After preparing the yaml template, you may deploy the Sentinel RLS token server:
  39. ```bash
  40. kubectl apply -f sample/k8s/sentinel-rls.yml
  41. ```
  42. ## Deploy Envoy
  43. Next we could deploy the Envoy instances in the K8S cluster. If you've already had Envoy instances running,
  44. you could configure the address (`sentinel-rls-service`) and the port (`10245`)
  45. of the rate limit cluster in your Envoy configuration.
  46. We've provided a deployment template for Envoy in `envoy.yml`.
  47. It includes:
  48. - A `ConfigMap` that contains the configuration for Envoy.
  49. This will be mounted as a file in the target `Deployment`, which will be loaded as the configuration
  50. file by Envoy.
  51. - A `Deployment` for Envoy. It will mount the `ConfigMap` as a volume
  52. for configuration.
  53. - A `Service` that exports the Envoy endpoint port (by default 10000) on a cluster-internal IP
  54. so that it could be accessible from other pods. If you need external access, you could choose the
  55. `LoadBalancer` type or add a frontend ingress.
  56. In the sample, we have two [Envoy clusters](https://www.envoyproxy.io/docs/envoy/latest/api-v2/clusters/clusters):
  57. - `service_httpbin`: HTTP proxy to `httpbin.org`
  58. - `rate_limit_cluster`: the cluster of the Sentinel RLS token server
  59. This route configuration tells Envoy to route incoming requests to `httpbin.org`. In the `http_filters` conf item,
  60. we added the `envoy.rate_limit` filter to the filter chain so that the global rate limiting is enabled.
  61. We set the rate limit domain as `foo`, which matches the item in the Envoy RLS rule.
  62. In the `route_config`, we provide the rate limit action: `{destination_cluster: {}}`, which will
  63. generate the rate limit descriptor containing the actual target cluster name (e.g. `service_httpbin`).
  64. Then we could set rate limit rules for each target clusters.
  65. After preparing the yaml template, you may deploy the Envoy instance:
  66. ```bash
  67. kubectl apply -f sample/k8s/envoy.yml
  68. ```
  69. ## Test the rate limiting
  70. Now it's show time! We could visit the URL `envoy-service:10000/json` in K8S pods.
  71. Since we set the max QPS to 1, we could emit concurrent requests to the URL, and we
  72. could see the first request passes, while the latter requests are blocked (status 429):
  73. ![image](https://user-images.githubusercontent.com/9434884/68571798-d0a46500-049e-11ea-8488-5e90f56f23a5.png)
  74. ## Update the rules dynamically
  75. You could update the rules in the `sentinel-rule-cm` ConfigMap. Once the content is updated,
  76. Sentinel will perceive the changes and load the new rules to `EnvoyRlsRuleManager`.