Skip to content

Commit b3f666d

Browse files
committed
chore(redis): support redis sentinel proxy
1 parent 99eba89 commit b3f666d

27 files changed

Lines changed: 596 additions & 126 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Return the proper Redis Sentinel image name
1414
{{ include "common.images.image" (dict "imageRoot" .Values.sentinel.image "global" .Values.global) }}
1515
{{- end -}}
1616

17+
{{/*
18+
Return the proper Redis Proxy image name
19+
*/}}
20+
{{- define "redis.proxy.image" -}}
21+
{{ include "common.images.image" (dict "imageRoot" .Values.proxy.image "global" .Values.global) }}
22+
{{- end -}}
23+
1724
{{/*
1825
Return the proper image name (for the metrics image)
1926
*/}}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ spec:
3030
{{- if .Values.sentinel.enabled }}
3131
- port: {{ .Values.sentinel.containerPorts.sentinel }}
3232
{{- end }}
33+
{{- if .Values.proxy.enabled }}
34+
- port: {{ .Values.proxy.containerPorts.proxy }}
35+
{{- end }}
3336
to:
3437
- podSelector:
3538
matchLabels: {{- include "common.labels.matchLabels" . | nindent 14 }}
@@ -48,6 +51,9 @@ spec:
4851
{{- if .Values.sentinel.enabled }}
4952
- port: {{ .Values.sentinel.containerPorts.sentinel }}
5053
{{- end }}
54+
{{- if .Values.proxy.enabled }}
55+
- port: {{ .Values.proxy.containerPorts.proxy }}
56+
{{- end }}
5157
{{- if not .Values.networkPolicy.allowExternal }}
5258
from:
5359
- podSelector:

addons/redis/7.0/chart/redis/templates/sentinel/node-services.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
{{ $sentinelport := 0}}
88
{{ $redisport := 0}}
9+
{{ $proxyport := 0}}
910
{{- if $portsmap }}
1011
{{ $sentinelport = index $portsmap (printf "%s-node-%s-%s" (include "common.names.fullname" $) (toString $i) "sentinel") }}
1112
{{ $redisport = index $portsmap (printf "%s-node-%s-%s" (include "common.names.fullname" $) (toString $i) "redis") }}
13+
{{ $proxyport = index $portsmap (printf "%s-node-%s-%s" (include "common.names.fullname" $) (toString $i) "proxy") }}
1214
{{- else }}
1315
{{- end }}
1416

@@ -45,6 +47,16 @@ spec:
4547
{{- end }}
4648
protocol: TCP
4749
targetPort: {{ $.Values.sentinel.containerPorts.sentinel }}
50+
- name: proxy
51+
{{- if $.Values.sentinel.service.nodePorts.proxy }}
52+
nodePort: {{ (add $.Values.sentinel.service.nodePorts.proxy $i 1) }}
53+
port: {{ (add $.Values.sentinel.service.nodePorts.proxy $i 1) }}
54+
{{- else }}
55+
nodePort: {{ $proxyport }}
56+
port: {{ $proxyport }}
57+
{{- end }}
58+
protocol: TCP
59+
targetPort: {{ $.Values.proxy.containerPorts.proxy }}
4860
- name: redis
4961
{{- if $.Values.sentinel.service.nodePorts.redis }}
5062
nodePort: {{ (add $.Values.sentinel.service.nodePorts.redis $i 1) }}
@@ -60,6 +72,11 @@ spec:
6072
port: {{ $.Values.sentinel.containerPorts.sentinel }}
6173
protocol: TCP
6274
targetPort: {{ $.Values.sentinel.containerPorts.sentinel }}
75+
- name: proxy-internal
76+
nodePort: null
77+
port: {{ $.Values.proxy.containerPorts.proxy }}
78+
protocol: TCP
79+
targetPort: {{ $.Values.proxy.containerPorts.proxy }}
6380
- name: redis-internal
6481
nodePort: null
6582
port: {{ $.Values.replica.containerPorts.redis }}

addons/redis/7.0/chart/redis/templates/sentinel/service.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
{{ $portsmap := (lookup "v1" "ConfigMap" $.Release.Namespace (printf "%s-%s" ( include "common.names.fullname" . ) "ports-configmap")).data }}
66

77
{{ $sentinelport := 0}}
8+
{{ $proxyport := 0}}
89
{{ $redisport := 0}}
910
{{- if $portsmap }}
1011
{{ $sentinelport = index $portsmap (printf "%s-%s" (include "common.names.fullname" $) "sentinel") }}
12+
{{ $proxyport = index $portsmap (printf "%s-%s" (include "common.names.fullname" $) "proxy") }}
1113
{{ $redisport = index $portsmap (printf "%s-%s" (include "common.names.fullname" $) "redis") }}
1214
{{- else }}
1315
{{- end }}
@@ -78,6 +80,22 @@ spec:
7880
{{- else if eq .Values.sentinel.service.type "NodePort" }}
7981
nodePort: {{ $sentinelport }}
8082
{{- end }}
83+
- name: tcp-proxy
84+
{{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.proxy }}
85+
port: {{ .Values.sentinel.service.nodePorts.proxy }}
86+
{{- else if eq .Values.sentinel.service.type "NodePort" }}
87+
port: {{ $proxyport }}
88+
{{- else }}
89+
port: {{ .Values.sentinel.service.ports.proxy }}
90+
{{- end }}
91+
targetPort: {{ .Values.proxy.containerPorts.proxy }}
92+
{{- if and (or (eq .Values.sentinel.service.type "NodePort") (eq .Values.sentinel.service.type "LoadBalancer")) .Values.sentinel.service.nodePorts.proxy }}
93+
nodePort: {{ .Values.sentinel.service.nodePorts.proxy }}
94+
{{- else if eq .Values.sentinel.service.type "ClusterIP" }}
95+
nodePort: null
96+
{{- else if eq .Values.sentinel.service.type "NodePort" }}
97+
nodePort: {{ $proxyport }}
98+
{{- end }}
8199
{{- if eq .Values.sentinel.service.type "NodePort" }}
82100
- name: sentinel-internal
83101
nodePort: null

addons/redis/7.0/chart/redis/templates/sentinel/statefulset.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,90 @@ spec:
443443
{{- if .Values.sentinel.extraVolumeMounts }}
444444
{{- include "common.tplvalues.render" ( dict "value" .Values.sentinel.extraVolumeMounts "context" $ ) | nindent 12 }}
445445
{{- end }}
446+
{{- if .Values.proxy.enabled }}
447+
- name: proxy
448+
image: {{ template "redis.proxy.image" . }}
449+
imagePullPolicy: {{ .Values.proxy.image.pullPolicy | quote }}
450+
{{- if .Values.diagnosticMode.enabled }}
451+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
452+
{{- else }}
453+
command:
454+
- init-stack
455+
{{- end }}
456+
{{- if .Values.diagnosticMode.enabled }}
457+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
458+
{{- else }}
459+
args:
460+
- bash
461+
- -ec
462+
- |
463+
[[ -f "$REDIS_PASSWORD_FILE" ]] && export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
464+
/opt/drycc/redis-sentinel/bin/reids-sentinel-proxy \
465+
-listen :{{ .Values.proxy.containerPorts.proxy }} \
466+
-master {{ .Values.sentinel.masterSet }} \
467+
-sentinel-addr ${POD_IP}:{{ .Values.sentinel.containerPorts.sentinel }} \
468+
-sentinel-pass $(REDIS_PASSWORD) \
469+
-sentinel-user ""
470+
{{- end }}
471+
env:
472+
- name: POD_IP
473+
valueFrom:
474+
fieldRef:
475+
fieldPath: status.podIP
476+
{{- if .Values.auth.enabled }}
477+
{{- if .Values.auth.usePasswordFiles }}
478+
- name: REDIS_PASSWORD_FILE
479+
value: "/opt/drycc/redis/secrets/redis-password"
480+
{{- else }}
481+
- name: REDIS_PASSWORD
482+
valueFrom:
483+
secretKeyRef:
484+
name: {{ template "redis.secretName" . }}
485+
key: {{ template "redis.secretPasswordKey" . }}
486+
{{- end }}
487+
{{- else }}
488+
- name: ALLOW_EMPTY_PASSWORD
489+
value: "yes"
490+
{{- end }}
491+
ports:
492+
- name: redis-proxy
493+
containerPort: {{ .Values.proxy.containerPorts.proxy }}
494+
{{- if not .Values.diagnosticMode.enabled }}
495+
{{- if .Values.proxy.startupProbe.enabled }}
496+
startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.sentinel.startupProbe "enabled") "context" $) | nindent 12 }}
497+
tcpSocket:
498+
port: redis-proxy
499+
{{- end }}
500+
{{- if .Values.proxy.livenessProbe.enabled }}
501+
livenessProbe:
502+
initialDelaySeconds: {{ .Values.proxy.livenessProbe.initialDelaySeconds }}
503+
periodSeconds: {{ .Values.proxy.livenessProbe.periodSeconds }}
504+
timeoutSeconds: {{ .Values.proxy.livenessProbe.timeoutSeconds }}
505+
successThreshold: {{ .Values.proxy.livenessProbe.successThreshold }}
506+
failureThreshold: {{ .Values.proxy.livenessProbe.failureThreshold }}
507+
tcpSocket:
508+
port: redis-proxy
509+
{{- end }}
510+
{{- if .Values.proxy.readinessProbe.enabled }}
511+
readinessProbe:
512+
initialDelaySeconds: {{ .Values.proxy.readinessProbe.initialDelaySeconds }}
513+
periodSeconds: {{ .Values.proxy.readinessProbe.periodSeconds }}
514+
timeoutSeconds: {{ .Values.proxy.readinessProbe.timeoutSeconds }}
515+
successThreshold: {{ .Values.proxy.readinessProbe.successThreshold }}
516+
failureThreshold: {{ .Values.proxy.readinessProbe.failureThreshold }}
517+
tcpSocket:
518+
port: redis-proxy
519+
{{- end }}
520+
{{- end }}
521+
{{- if .Values.proxy.resources }}
522+
resources: {{- toYaml .Values.proxy.resources | nindent 12 }}
523+
{{- end }}
524+
{{- if .Values.auth.usePasswordFiles }}
525+
volumeMounts:
526+
- name: redis-password
527+
mountPath: /opt/drycc/redis/secrets/
528+
{{- end }}
529+
{{- end }}
446530
{{- if .Values.metrics.enabled }}
447531
- name: metrics
448532
image: {{ template "redis.metrics.image" . }}

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ sentinel:
11201120
ports:
11211121
redis: 6379
11221122
sentinel: 26379
1123+
proxy: 36379
11231124
## @param sentinel.service.nodePorts.redis Node port for Redis&trade;
11241125
## @param sentinel.service.nodePorts.sentinel Node port for Sentinel
11251126
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
@@ -1129,6 +1130,7 @@ sentinel:
11291130
##
11301131
nodePorts:
11311132
redis: ""
1133+
proxy: ""
11321134
sentinel: ""
11331135
## @param sentinel.service.externalTrafficPolicy Redis&trade; Sentinel service external traffic policy
11341136
## ref: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip
@@ -1158,6 +1160,119 @@ sentinel:
11581160
##
11591161
terminationGracePeriodSeconds: 30
11601162

1163+
## @section Redis&trade; Sentinel configuration parameters
1164+
##
1165+
1166+
proxy:
1167+
## @param sentinel.enabled Use Redis&trade; Sentinel on Redis&trade; pods.
1168+
## IMPORTANT: this will disable the master and replicas services and
1169+
## create a single Redis&trade; service exposing both the Redis and Sentinel ports
1170+
##
1171+
enabled: true
1172+
## Bitnami Redis&trade; Sentinel image version
1173+
## ref: https://hub.docker.com/r/bitnami/redis-sentinel/tags/
1174+
## @param sentinel.image.registry Redis&trade; Sentinel image registry
1175+
## @param sentinel.image.repository Redis&trade; Sentinel image repository
1176+
## @param sentinel.image.tag Redis&trade; Sentinel image tag (immutable tags are recommended)
1177+
## @param sentinel.image.pullPolicy Redis&trade; Sentinel image pull policy
1178+
## @param sentinel.image.pullSecrets Redis&trade; Sentinel image pull secrets
1179+
## @param sentinel.image.debug Enable image debug mode
1180+
##
1181+
## todo: support both of amd64 and arm64
1182+
image:
1183+
registry: registry.drycc.cc
1184+
repository: drycc-addons/redis-sentinel
1185+
tag: "7.0"
1186+
## Specify a imagePullPolicy
1187+
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
1188+
## ref: https://kubernetes.io/docs/user-guide/images/#pre-pulling-images
1189+
##
1190+
pullPolicy: IfNotPresent
1191+
## Optionally specify an array of imagePullSecrets.
1192+
## Secrets must be manually created in the namespace.
1193+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
1194+
## e.g:
1195+
## pullSecrets:
1196+
## - myRegistryKeySecretName
1197+
##
1198+
pullSecrets: []
1199+
## Enable debug mode
1200+
##
1201+
debug: false
1202+
## @param sentinel.command Override default container command (useful when using custom images)
1203+
##
1204+
command: []
1205+
## @param sentinel.args Override default container args (useful when using custom images)
1206+
##
1207+
args: []
1208+
## @param sentinel.preExecCmds Additional commands to run prior to starting Redis&trade; Sentinel
1209+
##
1210+
preExecCmds: []
1211+
## Configure extra options for Redis&trade; containers' liveness and readiness probes
1212+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes
1213+
## @param sentinel.startupProbe.enabled Enable startupProbe on Redis&trade; Sentinel nodes
1214+
## @param sentinel.startupProbe.initialDelaySeconds Initial delay seconds for startupProbe
1215+
## @param sentinel.startupProbe.periodSeconds Period seconds for startupProbe
1216+
## @param sentinel.startupProbe.timeoutSeconds Timeout seconds for startupProbe
1217+
## @param sentinel.startupProbe.failureThreshold Failure threshold for startupProbe
1218+
## @param sentinel.startupProbe.successThreshold Success threshold for startupProbe
1219+
##
1220+
startupProbe:
1221+
enabled: true
1222+
initialDelaySeconds: 10
1223+
periodSeconds: 10
1224+
timeoutSeconds: 5
1225+
successThreshold: 1
1226+
failureThreshold: 22
1227+
## @param sentinel.livenessProbe.enabled Enable livenessProbe on Redis&trade; Sentinel nodes
1228+
## @param sentinel.livenessProbe.initialDelaySeconds Initial delay seconds for livenessProbe
1229+
## @param sentinel.livenessProbe.periodSeconds Period seconds for livenessProbe
1230+
## @param sentinel.livenessProbe.timeoutSeconds Timeout seconds for livenessProbe
1231+
## @param sentinel.livenessProbe.failureThreshold Failure threshold for livenessProbe
1232+
## @param sentinel.livenessProbe.successThreshold Success threshold for livenessProbe
1233+
##
1234+
livenessProbe:
1235+
enabled: true
1236+
initialDelaySeconds: 20
1237+
periodSeconds: 5
1238+
timeoutSeconds: 5
1239+
successThreshold: 1
1240+
failureThreshold: 5
1241+
## @param sentinel.readinessProbe.enabled Enable readinessProbe on Redis&trade; Sentinel nodes
1242+
## @param sentinel.readinessProbe.initialDelaySeconds Initial delay seconds for readinessProbe
1243+
## @param sentinel.readinessProbe.periodSeconds Period seconds for readinessProbe
1244+
## @param sentinel.readinessProbe.timeoutSeconds Timeout seconds for readinessProbe
1245+
## @param sentinel.readinessProbe.failureThreshold Failure threshold for readinessProbe
1246+
## @param sentinel.readinessProbe.successThreshold Success threshold for readinessProbe
1247+
##
1248+
readinessProbe:
1249+
enabled: true
1250+
initialDelaySeconds: 20
1251+
periodSeconds: 5
1252+
timeoutSeconds: 1
1253+
successThreshold: 1
1254+
failureThreshold: 5
1255+
## Redis&trade; Sentinel resource requests and limits
1256+
## ref: https://kubernetes.io/docs/user-guide/compute-resources/
1257+
## @param sentinel.resources.limits The resources limits for the Redis&trade; Sentinel containers
1258+
## @param sentinel.resources.requests The requested resources for the Redis&trade; Sentinel containers
1259+
##
1260+
resources:
1261+
limits: {}
1262+
requests: {}
1263+
## Configure Container Security Context
1264+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod
1265+
## @param sentinel.containerSecurityContext.enabled Enabled Redis&trade; Sentinel containers' Security Context
1266+
## @param sentinel.containerSecurityContext.runAsUser Set Redis&trade; Sentinel containers' Security Context runAsUser
1267+
##
1268+
containerSecurityContext:
1269+
enabled: true
1270+
runAsUser: 1001
1271+
## @param proxy.containerPorts.proxy Container port to open on Redis&trade; Sentinel nodes
1272+
##
1273+
containerPorts:
1274+
proxy: 36379
1275+
11611276
## @section Other Parameters
11621277
##
11631278

addons/redis/7.0/meta.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ allow_parameters:
3333
- name: "sentinel.enabled"
3434
required: false
3535
description: "sentinel enabled type config for values.yaml"
36+
- name: "proxy.enabled"
37+
required: false
38+
description: "proxy enabled type config for values.yaml"
3639
- name: "metrics.enable"
3740
required: false
3841
description: "metrics enable or not config for values.yaml"

0 commit comments

Comments
 (0)