Skip to content

Commit 569342b

Browse files
committed
chore(redis-cluster): optimize redis-cluster-proxy
1 parent 566f425 commit 569342b

5 files changed

Lines changed: 56 additions & 95 deletions

File tree

addons/redis-cluster/7.0/chart/redis-cluster/templates/configmap.yaml

Lines changed: 33 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -12,93 +12,39 @@ metadata:
1212
{{- end }}
1313
data:
1414
{{- if .Values.proxy.enabled }}
15-
redis-proxy-default.yaml: |-
16-
overload_manager:
17-
resource_monitors:
18-
- name: "envoy.resource_monitors.global_downstream_max_connections"
19-
typed_config:
20-
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
21-
max_active_downstream_connections: 10000
22-
static_resources:
23-
listeners:
24-
- name: redis_listener
25-
address:
26-
socket_address:
27-
address: 0.0.0.0
28-
port_value: {{ .Values.proxy.containerPorts.proxy }}
29-
filter_chains:
30-
- filters:
31-
- name: envoy.filters.network.redis_proxy
32-
typed_config:
33-
"@type": type.googleapis.com/envoy.extensions.filters.network.redis_proxy.v3.RedisProxy
34-
stat_prefix: egress_redis
35-
settings:
36-
op_timeout: 5s
37-
prefix_routes:
38-
catch_all_route:
39-
cluster: redis_cluster
40-
downstream_auth_username:
41-
inline_string: "default"
42-
downstream_auth_passwords:
43-
- inline_string: {REDIS_PASSWORD}
44-
{{- if .Values.tls.enabled }}
45-
transport_socket:
46-
name: envoy.transport_sockets.tls
47-
typed_config:
48-
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
49-
require_client_certificate: true
50-
common_tls_context:
51-
tls_certificates:
52-
- certificate_chain:
53-
filename: {{ template "redis-cluster.tlsCert" . }}
54-
private_key:
55-
filename: {{ template "redis-cluster.tlsCertKey" . }}
56-
validation_context:
57-
trusted_ca:
58-
filename: {{ template "redis-cluster.tlsCACert" . }}
59-
{{- end }}
60-
clusters:
61-
- name: redis_cluster
62-
cluster_type:
63-
name: envoy.clusters.redis
64-
typed_config:
65-
"@type": type.googleapis.com/google.protobuf.Struct
66-
value:
67-
cluster_refresh_rate: 10s
68-
cluster_refresh_timeout: 4s
69-
connect_timeout: 4s
70-
dns_lookup_family: V4_ONLY
71-
lb_policy: CLUSTER_PROVIDED
72-
load_assignment:
73-
cluster_name: redis_cluster
74-
endpoints:
75-
lb_endpoints:
76-
endpoint:
77-
address:
78-
socket_address: { address: 127.0.0.1, port_value: {{ .Values.redis.containerPorts.redis | quote }} }
79-
typed_extension_protocol_options:
80-
envoy.filters.network.redis_proxy:
81-
"@type": type.googleapis.com/google.protobuf.Struct
82-
value:
83-
auth_username:
84-
inline_string: "default"
85-
auth_password:
86-
inline_string: {REDIS_PASSWORD}
87-
{{- if .Values.tls.enabled }}
88-
transport_socket:
89-
name: envoy.transport_sockets.tls
90-
typed_config:
91-
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
92-
common_tls_context:
93-
tls_certificates:
94-
certificate_chain:
95-
filename: {{ template "redis-cluster.tlsCert" . }}
96-
private_key:
97-
filename: {{ template "redis-cluster.tlsCertKey" . }}
98-
validation_context:
99-
trusted_ca:
100-
filename: {{ template "redis-cluster.tlsCACert" . }}
101-
{{- end }}
15+
redis-proxy-default.toml: |-
16+
[log]
17+
level = "libredis_proxy=warn" # "trace" "info" "debug" "warn" "error"
18+
ansi = true # support ANSI colors
19+
stdout = true # print logs to stdout
20+
directory = "/tmp" # log file directory
21+
file_name = "redis-proxy.log" # log file name
22+
23+
[metrics]
24+
port = 2110
25+
26+
[[clusters]]
27+
name = "redis-cluster-proxy"
28+
listen_addr = "0.0.0.0:{{ .Values.proxy.containerPorts.proxy }}"
29+
hash_tag = "{}"
30+
thread = 1
31+
cache_type = "redis_cluster"
32+
servers = ["127.0.0.1:{{ .Values.redis.containerPorts.redis }}"]
33+
34+
fetch_interval = 1800000 # 1800s , 30 minutes
35+
fetch_since_latest_cmd = 1000 # 3600s , 1 hour
36+
read_from_slave = false
37+
38+
ping_fail_limit = 10
39+
ping_interval = 300
40+
41+
read_timeout = 1000
42+
write_timeout = 1000
43+
dial_timeout = 500
44+
listen_proto = "tcp"
45+
node_connections = 1
46+
47+
auth = {REDIS_PASSWORD}
10248
{{- end }}
10349
redis-default.conf: |-
10450
# Redis configuration file example.

addons/redis-cluster/7.0/chart/redis-cluster/templates/headless-svc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ spec:
2121
- name: tcp-redis-bus
2222
port: {{ .Values.redis.containerPorts.bus }}
2323
targetPort: tcp-redis-bus
24+
- name: tcp-redis-proxy
25+
port: {{ .Values.proxy.containerPorts.proxy }}
26+
targetPort: tcp-redis-proxy
2427
selector: {{- include "common.labels.matchLabels" . | nindent 4 }}

addons/redis-cluster/7.0/chart/redis-cluster/templates/networkpolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ spec:
4040
- ports:
4141
- port: {{ .Values.redis.containerPorts.redis }}
4242
- port: {{ .Values.redis.containerPorts.bus }}
43+
- port: {{ .Values.proxy.containerPorts.proxy }}
4344
from:
4445
{{- if .Values.networkPolicy.allowCurrentNamespace }}
4546
- namespaceSelector:

addons/redis-cluster/7.0/chart/redis-cluster/templates/redis-statefulset.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,19 @@ spec:
301301
command: ['init-stack', '/bin/bash', '-c']
302302
args:
303303
- |
304-
# Start envoy redis proxy
304+
while true; do
305+
sleep 1
306+
/scripts/ping_readiness_local.sh 1
307+
if [ $? -eq 0 ]; then
308+
break
309+
fi
310+
done
311+
# Start redis cluster proxy
305312
{{- if .Values.usePasswordFile }}
306313
export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
307314
{{- end }}
308-
sed s/{REDIS_PASSWORD}/${REDIS_PASSWORD}/g /opt/drycc/redis/etc/redis-proxy-default.yaml > /opt/drycc/redis/etc/redis-proxy.yaml
309-
envoy -c /opt/drycc/redis/etc/redis-proxy.yaml --log-level error --concurrency 0
315+
sed s/{REDIS_PASSWORD}/\"${REDIS_PASSWORD}\"/g /opt/drycc/redis/etc/redis-proxy-default.toml > /opt/drycc/redis/etc/redis-proxy.toml
316+
redis-cluster-proxy /opt/drycc/redis/etc/redis-proxy.toml
310317
{{- end }}
311318
env:
312319
{{- if and .Values.usePassword (not .Values.usePasswordFile) }}
@@ -320,6 +327,8 @@ spec:
320327
- name: REDIS_PASSWORD_FILE
321328
value: "/opt/drycc/redis/secrets/redis-password"
322329
{{- end }}
330+
- name: REDIS_PORT
331+
value: {{ .Values.redis.containerPorts.redis | quote }}
323332
ports:
324333
- name: tcp-proxy
325334
containerPort: {{ .Values.proxy.containerPorts.proxy }}
@@ -362,9 +371,11 @@ spec:
362371
{{- include "common.tplvalues.render" (dict "value" .Values.proxy.resources "context" $) | nindent 12 }}
363372
{{- end }}
364373
volumeMounts:
374+
- name: scripts
375+
mountPath: /scripts
365376
- name: default-config
366-
mountPath: /opt/drycc/redis/etc/redis-proxy-default.yaml
367-
subPath: redis-proxy-default.yaml
377+
mountPath: /opt/drycc/redis/etc/redis-proxy-default.toml
378+
subPath: redis-proxy-default.toml
368379
{{- if .Values.usePasswordFile }}
369380
- name: redis-password
370381
mountPath: /opt/drycc/redis/secrets/

addons/redis-cluster/7.0/chart/redis-cluster/templates/scripts-configmap.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data:
2626
response=$(
2727
timeout -s 3 $1 \
2828
redis-cli \
29-
-h localhost \
29+
-h 127.0.0.1 \
3030
{{- if .Values.tls.enabled }}
3131
-p $REDIS_TLS_PORT \
3232
--tls \
@@ -51,7 +51,7 @@ data:
5151
response=$(
5252
timeout -s 3 $1 \
5353
redis-cli \
54-
-h localhost \
54+
-h 127.0.0.1 \
5555
{{- if .Values.tls.enabled }}
5656
-p $REDIS_TLS_PORT \
5757
--tls \
@@ -88,7 +88,7 @@ data:
8888
response=$(
8989
timeout -s 3 $1 \
9090
redis-cli \
91-
-h localhost \
91+
-h 127.0.0.1 \
9292
{{- if .Values.tls.enabled }}
9393
-p $REDIS_TLS_PORT \
9494
--tls \

0 commit comments

Comments
 (0)