-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rate Limit using Istio Envoy (#674)
* add rate limit * seperate template files and add ratelimit enable flag * set istio injection to false * set ratelimit requestsPerUnit to 10000 * change the name and namespace of ratelimit
- Loading branch information
1 parent
050d350
commit 12e86a2
Showing
15 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
build/charts/yorkie-cluster/templates/istio/ratelimit/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ .Values.ratelimit.name }}-config | ||
namespace: istio-system | ||
data: | ||
config.yaml: | | ||
domain: {{ .Values.ratelimit.domain }} | ||
descriptors: | ||
- key: PATH | ||
rate_limit: | ||
unit: {{ .Values.ratelimit.unit }} | ||
requests_per_unit: {{ .Values.ratelimit.requestsPerUnit }} | ||
{{ end }} |
56 changes: 56 additions & 0 deletions
56
build/charts/yorkie-cluster/templates/istio/ratelimit/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.ratelimit.name }} | ||
namespace: istio-system | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.ratelimit.name }} | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: ratelimit | ||
spec: | ||
containers: | ||
- image: envoyproxy/ratelimit:9d8d70a8 # 2022/08/16 | ||
imagePullPolicy: Always | ||
name: ratelimit | ||
command: ["/bin/ratelimit"] | ||
env: | ||
- name: LOG_LEVEL | ||
value: debug | ||
- name: REDIS_SOCKET_TYPE | ||
value: tcp | ||
- name: REDIS_URL | ||
value: {{ .Values.ratelimit.name }}-redis:6379 | ||
- name: USE_STATSD | ||
value: "false" | ||
- name: RUNTIME_ROOT | ||
value: /data | ||
- name: RUNTIME_SUBDIRECTORY | ||
value: ratelimit | ||
- name: RUNTIME_WATCH_ROOT | ||
value: "false" | ||
- name: RUNTIME_IGNOREDOTFILES | ||
value: "true" | ||
- name: HOST | ||
value: "::" | ||
- name: GRPC_HOST | ||
value: "::" | ||
ports: | ||
- containerPort: 8080 | ||
- containerPort: 8081 | ||
- containerPort: 6070 | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /data/ratelimit/config | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: ratelimit-config | ||
{{ end }} |
65 changes: 65 additions & 0 deletions
65
build/charts/yorkie-cluster/templates/istio/ratelimit/envoy-filter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: EnvoyFilter | ||
metadata: | ||
name: filter-ratelimit | ||
namespace: istio-system | ||
spec: | ||
workloadSelector: | ||
labels: | ||
istio: ingressgateway | ||
configPatches: | ||
- applyTo: HTTP_FILTER | ||
match: | ||
context: GATEWAY | ||
listener: | ||
filterChain: | ||
filter: | ||
name: "envoy.filters.network.http_connection_manager" | ||
subFilter: | ||
name: "envoy.filters.http.router" | ||
patch: | ||
operation: INSERT_BEFORE | ||
value: | ||
name: envoy.filters.http.ratelimit | ||
typed_config: | ||
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimit | ||
# Match it to the ratelimit service config | ||
domain: {{ .Values.ratelimit.domain }} | ||
failure_mode_deny: true | ||
timeout: 10s | ||
rate_limit_service: | ||
grpc_service: | ||
envoy_grpc: | ||
cluster_name: outbound|8081||{{ .Values.ratelimit.name }}.istio-system.svc.cluster.local | ||
authority: {{ .Values.ratelimit.name }}.istio-system.svc.cluster.local | ||
transport_api_version: V3 | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: EnvoyFilter | ||
metadata: | ||
name: filter-ratelimit-svc | ||
namespace: istio-system | ||
spec: | ||
workloadSelector: | ||
labels: | ||
istio: ingressgateway | ||
configPatches: | ||
- applyTo: VIRTUAL_HOST | ||
match: | ||
context: GATEWAY | ||
routeConfiguration: | ||
vhost: | ||
name: "" | ||
route: | ||
action: ANY | ||
patch: | ||
operation: MERGE | ||
# Applies the rate limit rules. | ||
value: | ||
rate_limits: | ||
- actions: | ||
- request_headers: | ||
header_name: ":path" | ||
descriptor_key: "PATH" | ||
{{ end }} |
26 changes: 26 additions & 0 deletions
26
build/charts/yorkie-cluster/templates/istio/ratelimit/redis/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.ratelimit.name }}-redis | ||
namespace: istio-system | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: redis | ||
template: | ||
metadata: | ||
labels: | ||
app: redis | ||
spec: | ||
containers: | ||
- image: redis:alpine | ||
imagePullPolicy: Always | ||
name: redis | ||
ports: | ||
- name: redis | ||
containerPort: 6379 | ||
restartPolicy: Always | ||
serviceAccountName: "" | ||
{{ end }} |
15 changes: 15 additions & 0 deletions
15
build/charts/yorkie-cluster/templates/istio/ratelimit/redis/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Values.ratelimit.name }}-redis | ||
namespace: istio-system | ||
labels: | ||
app: redis | ||
spec: | ||
ports: | ||
- name: redis | ||
port: 6379 | ||
selector: | ||
app: redis | ||
{{ end }} |
25 changes: 25 additions & 0 deletions
25
build/charts/yorkie-cluster/templates/istio/ratelimit/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{ if .Values.ratelimit.enabled }} | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Values.ratelimit.name }} | ||
namespace: istio-system | ||
labels: | ||
app: {{ .Values.ratelimit.name }} | ||
spec: | ||
ports: | ||
- name: http-port | ||
port: 8080 | ||
targetPort: 8080 | ||
protocol: TCP | ||
- name: grpc-port | ||
port: 8081 | ||
targetPort: 8081 | ||
protocol: TCP | ||
- name: http-debug | ||
port: 6070 | ||
targetPort: 6070 | ||
protocol: TCP | ||
selector: | ||
app: ratelimit | ||
{{ end }} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters