Skip to content

Commit 96926e7

Browse files
committed
chore(redis-cluster): add redis cluster proxy
1 parent b3f666d commit 96926e7

26 files changed

Lines changed: 527 additions & 9 deletions

File tree

addons/redis-cluster/7.0/chart/redis-cluster/templates/_helpers.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Return the proper Redis® image name
77
{{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
88
{{- end -}}
99

10+
{{/*
11+
Return the proper Redis® image name
12+
*/}}
13+
{{- define "redis-cluster.proxy.image" -}}
14+
{{ include "common.images.image" (dict "imageRoot" .Values.proxy.image "global" .Values.global) }}
15+
{{- end -}}
16+
1017
{{/*
1118
Return the proper image name (for the metrics image)
1219
*/}}

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,95 @@ metadata:
1111
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
1212
{{- end }}
1313
data:
14+
{{- 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 }}
102+
{{- end }}
14103
redis-default.conf: |-
15104
# Redis configuration file example.
16105
#

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
@@ -28,6 +28,7 @@ spec:
2828
- ports:
2929
- port: {{ .Values.redis.containerPorts.redis }}
3030
- port: {{ .Values.redis.containerPorts.bus }}
31+
- port: {{ .Values.proxy.containerPorts.proxy }}
3132
to:
3233
- podSelector:
3334
matchLabels: {{- include "common.labels.matchLabels" . | nindent 14 }}

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,94 @@ spec:
287287
{{- if .Values.redis.extraVolumeMounts }}
288288
{{- include "common.tplvalues.render" ( dict "value" .Values.redis.extraVolumeMounts "context" $ ) | nindent 12 }}
289289
{{- end }}
290+
{{- if .Values.proxy.enabled }}
291+
- name: proxy
292+
image: {{ include "redis-cluster.proxy.image" . }}
293+
imagePullPolicy: {{ .Values.proxy.image.pullPolicy | quote }}
294+
{{- if .Values.containerSecurityContext.enabled }}
295+
securityContext: {{- omit .Values.containerSecurityContext "enabled" | toYaml | nindent 12 }}
296+
{{- end }}
297+
{{- if .Values.diagnosticMode.enabled }}
298+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
299+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
300+
{{- else }}
301+
command: ['init-stack', '/bin/bash', '-c']
302+
args:
303+
- |
304+
# Start envoy redis proxy
305+
{{- if .Values.usePasswordFile }}
306+
export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
307+
{{- 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
310+
{{- end }}
311+
env:
312+
{{- if and .Values.usePassword (not .Values.usePasswordFile) }}
313+
- name: REDIS_PASSWORD
314+
valueFrom:
315+
secretKeyRef:
316+
name: {{ template "redis-cluster.secretName" . }}
317+
key: {{ template "redis-cluster.secretPasswordKey" . }}
318+
{{- end }}
319+
{{- if .Values.usePasswordFile }}
320+
- name: REDIS_PASSWORD_FILE
321+
value: "/opt/drycc/redis/secrets/redis-password"
322+
{{- end }}
323+
ports:
324+
- name: tcp-proxy
325+
containerPort: {{ .Values.proxy.containerPorts.proxy }}
326+
{{- if not .Values.diagnosticMode.enabled }}
327+
{{- if .Values.proxy.livenessProbe.enabled }}
328+
livenessProbe:
329+
tcpSocket:
330+
port: tcp-proxy
331+
initialDelaySeconds: {{ .Values.proxy.livenessProbe.initialDelaySeconds }}
332+
periodSeconds: {{ .Values.proxy.livenessProbe.periodSeconds }}
333+
# One second longer than command timeout should prevent generation of zombie processes.
334+
timeoutSeconds: {{ add1 .Values.proxy.livenessProbe.timeoutSeconds }}
335+
successThreshold: {{ .Values.proxy.livenessProbe.successThreshold }}
336+
failureThreshold: {{ .Values.proxy.livenessProbe.failureThreshold }}
337+
{{- end }}
338+
{{- if .Values.proxy.readinessProbe.enabled }}
339+
readinessProbe:
340+
tcpSocket:
341+
port: tcp-proxy
342+
initialDelaySeconds: {{ .Values.proxy.readinessProbe.initialDelaySeconds }}
343+
periodSeconds: {{ .Values.proxy.readinessProbe.periodSeconds }}
344+
# One second longer than command timeout should prevent generation of zombie processes.
345+
timeoutSeconds: {{ add1 .Values.proxy.readinessProbe.timeoutSeconds }}
346+
successThreshold: {{ .Values.proxy.readinessProbe.successThreshold }}
347+
failureThreshold: {{ .Values.proxy.readinessProbe.failureThreshold }}
348+
{{- end }}
349+
{{- if .Values.proxy.startupProbe.enabled }}
350+
startupProbe:
351+
tcpSocket:
352+
port: tcp-proxy
353+
initialDelaySeconds: {{ .Values.proxy.startupProbe.initialDelaySeconds }}
354+
periodSeconds: {{ .Values.proxy.startupProbe.periodSeconds }}
355+
timeoutSeconds: {{ .Values.proxy.startupProbe.timeoutSeconds }}
356+
successThreshold: {{ .Values.proxy.startupProbe.successThreshold }}
357+
failureThreshold: {{ .Values.proxy.startupProbe.failureThreshold }}
358+
{{- end }}
359+
{{- end }}
360+
{{- if .Values.proxy.resources }}
361+
resources:
362+
{{- include "common.tplvalues.render" (dict "value" .Values.proxy.resources "context" $) | nindent 12 }}
363+
{{- end }}
364+
volumeMounts:
365+
- name: default-config
366+
mountPath: /opt/drycc/redis/etc/redis-proxy-default.yaml
367+
subPath: redis-proxy-default.yaml
368+
{{- if .Values.usePasswordFile }}
369+
- name: redis-password
370+
mountPath: /opt/drycc/redis/secrets/
371+
{{- end }}
372+
{{- if .Values.tls.enabled }}
373+
- name: redis-certificates
374+
mountPath: /opt/drycc/redis/certs
375+
readOnly: true
376+
{{- end }}
377+
{{- end }}
290378
{{- if .Values.metrics.enabled }}
291379
- name: metrics
292380
image: {{ template "redis-cluster.metrics.image" . }}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ spec:
4747
{{- else if eq .Values.service.type "ClusterIP" }}
4848
nodePort: null
4949
{{- end }}
50+
- name: tcp-proxy
51+
port: {{ .Values.service.ports.proxy }}
52+
targetPort: tcp-proxy
53+
protocol: TCP
54+
{{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.proxy)) }}
55+
nodePort: {{ .Values.service.nodePorts.proxy }}
56+
{{- else if eq .Values.service.type "ClusterIP" }}
57+
nodePort: null
58+
{{- end }}
5059
{{- if .Values.service.extraPorts }}
5160
{{- include "common.tplvalues.render" (dict "value" .Values.service.extraPorts "context" $) | nindent 4 }}
5261
{{- end }}

addons/redis-cluster/7.0/chart/redis-cluster/values.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ service:
233233
##
234234
ports:
235235
redis: 6379
236+
proxy: 36379
236237
## Node ports to expose
237238
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
238239
## @param service.nodePorts.redis Node port for Redis
239240
##
240241
nodePorts:
241242
redis: ""
243+
proxy: ""
242244
## @param service.extraPorts Extra ports to expose in the service (normally used with the `sidecar` value)
243245
##
244246
extraPorts: []
@@ -723,6 +725,108 @@ updateJob:
723725
##
724726
requests: {}
725727

728+
729+
## @section Cluster proxy management parameters
730+
##
731+
732+
## Redis&reg; Cluster proxy settings
733+
##
734+
proxy:
735+
enabled: true
736+
## @param proxy.image.registry Redis&reg; exporter image registry
737+
## @param proxy.image.repository Redis&reg; exporter image name
738+
## @param proxy.image.tag Redis&reg; exporter image tag
739+
## @param proxy.image.digest Redis&reg; exporter image digest in the way sha256:aa.... Please note this parameter, if set, will override the tag
740+
## @param proxy.image.pullPolicy Redis&reg; exporter image pull policy
741+
## @param proxy.image.pullSecrets Specify docker-registry secret names as an array
742+
##
743+
image:
744+
registry: registry.drycc.cc
745+
repository: drycc-addons/redis-cluster
746+
tag: "7.0"
747+
digest: ""
748+
pullPolicy: IfNotPresent
749+
## Optionally specify an array of imagePullSecrets.
750+
## Secrets must be manually created in the namespace.
751+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
752+
## e.g:
753+
## pullSecrets:
754+
## - myRegistryKeySecretName
755+
##
756+
pullSecrets: []
757+
containerPorts:
758+
proxy: 36379
759+
## Container resource requests and limits
760+
## ref: https://kubernetes.io/docs/user-guide/compute-resources/
761+
## We usually recommend not to specify default resources and to leave this as a conscious
762+
## choice for the user. This also increases chances charts run on environments with little
763+
## resources, such as Minikube. If you do want to specify resources, uncomment the following
764+
## lines, adjust them as necessary, and remove the curly braces after 'resources:'.
765+
## @param updateJob.resources.limits The resources limits for the container
766+
## @param updateJob.resources.requests The requested resources for the container
767+
##
768+
resources:
769+
## Example:
770+
## limits:
771+
## cpu: 500m
772+
## memory: 1Gi
773+
##
774+
limits: {}
775+
## Examples:
776+
## requests:
777+
## cpu: 250m
778+
## memory: 256Mi
779+
##
780+
requests: {}
781+
## Configure extra options for Redis&reg; liveness probes
782+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes)
783+
## @param redis.livenessProbe.enabled Enable livenessProbe
784+
## @param redis.livenessProbe.initialDelaySeconds Initial delay seconds for livenessProbe
785+
## @param redis.livenessProbe.periodSeconds Period seconds for livenessProbe
786+
## @param redis.livenessProbe.timeoutSeconds Timeout seconds for livenessProbe
787+
## @param redis.livenessProbe.failureThreshold Failure threshold for livenessProbe
788+
## @param redis.livenessProbe.successThreshold Success threshold for livenessProbe
789+
##
790+
livenessProbe:
791+
enabled: true
792+
initialDelaySeconds: 5
793+
periodSeconds: 5
794+
timeoutSeconds: 5
795+
successThreshold: 1
796+
failureThreshold: 5
797+
## Configure extra options for Redis&reg; readiness probes
798+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes)
799+
## @param redis.readinessProbe.enabled Enable readinessProbe
800+
## @param redis.readinessProbe.initialDelaySeconds Initial delay seconds for readinessProbe
801+
## @param redis.readinessProbe.periodSeconds Period seconds for readinessProbe
802+
## @param redis.readinessProbe.timeoutSeconds Timeout seconds for readinessProbe
803+
## @param redis.readinessProbe.failureThreshold Failure threshold for readinessProbe
804+
## @param redis.readinessProbe.successThreshold Success threshold for readinessProbe
805+
##
806+
readinessProbe:
807+
enabled: true
808+
initialDelaySeconds: 5
809+
periodSeconds: 5
810+
timeoutSeconds: 1
811+
successThreshold: 1
812+
failureThreshold: 5
813+
## @param redis.startupProbe.enabled Enable startupProbe
814+
## @param redis.startupProbe.path Path to check for startupProbe
815+
## @param redis.startupProbe.initialDelaySeconds Initial delay seconds for startupProbe
816+
## @param redis.startupProbe.periodSeconds Period seconds for startupProbe
817+
## @param redis.startupProbe.timeoutSeconds Timeout seconds for startupProbe
818+
## @param redis.startupProbe.failureThreshold Failure threshold for startupProbe
819+
## @param redis.startupProbe.successThreshold Success threshold for startupProbe
820+
##
821+
startupProbe:
822+
enabled: false
823+
path: /
824+
initialDelaySeconds: 300
825+
periodSeconds: 10
826+
timeoutSeconds: 5
827+
failureThreshold: 6
828+
successThreshold: 1
829+
726830
## @section Cluster management parameters
727831
##
728832

addons/redis-cluster/7.0/plans/standard-1024/bind.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ credential:
1919
name: {{ template "common.names.fullname" . }}
2020
jsonpath: '{ .spec.ports[?(@.name=="tcp-redis")].port }'
2121

22+
- name: PROXY_PORT
23+
valueFrom:
24+
serviceRef:
25+
name: {{ template "common.names.fullname" . }}
26+
jsonpath: '{ .spec.ports[?(@.name=="tcp-proxy")].port }'
27+
2228
{{- if and .Values.usePassword (not .Values.existingSecret) }}
2329
- name: REDIS_PASSWORD
2430
valueFrom:

addons/redis-cluster/7.0/plans/standard-1024/values.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,20 @@ redis:
3030
memory: 1024Mi
3131
requests:
3232
cpu: 20m
33-
memory: 512Mi
33+
memory: 512Mi
34+
35+
## @section Proxy&reg; statefulset parameters
36+
##
37+
proxy:
38+
## Proxy&reg; resource requests and limits
39+
## ref: https://kubernetes.io/docs/user-guide/compute-resources/
40+
## @param proxy.resources.limits The resources limits for the container
41+
## @param proxy.resources.requests The requested resources for the container
42+
##
43+
resources:
44+
limits:
45+
cpu: 100m
46+
memory: 256Mi
47+
requests:
48+
cpu: 10m
49+
memory: 64Mi

0 commit comments

Comments
 (0)