From 0e4b542c611ab192e8cf8daaeeb4464d7121eda2 Mon Sep 17 00:00:00 2001 From: Amal Soman Date: Mon, 9 Sep 2019 08:21:17 +0530 Subject: [PATCH] [stable/redis-ha] Add a dedicated port in haproxy for redis slaves (#16824) * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves Signed-off-by: Amal Soman * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves Signed-off-by: Amal Soman * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves * [stable/redis-ha] Add a dedicated port in haproxy for redis slaves Signed-off-by: Amal Soman --- stable/redis-ha/Chart.yaml | 2 +- stable/redis-ha/README.md | 2 ++ .../templates/redis-ha-configmap.yaml | 33 ++++++++++++++++--- .../templates/redis-haproxy-deployment.yaml | 7 +++- .../templates/redis-haproxy-service.yaml | 8 ++++- stable/redis-ha/values.yaml | 5 +++ 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/stable/redis-ha/Chart.yaml b/stable/redis-ha/Chart.yaml index 1d5022bb875c..a8a694af2129 100644 --- a/stable/redis-ha/Chart.yaml +++ b/stable/redis-ha/Chart.yaml @@ -6,7 +6,7 @@ keywords: - redis - keyvalue - database -version: 3.7.5 +version: 3.7.6 appVersion: 5.0.5 description: Highly available Kubernetes implementation of Redis icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png diff --git a/stable/redis-ha/README.md b/stable/redis-ha/README.md index f13d5ba564d1..4fa7ff81029d 100644 --- a/stable/redis-ha/README.md +++ b/stable/redis-ha/README.md @@ -93,6 +93,8 @@ The following table lists the configurable parameters of the Redis chart and the | `haproxy.resources` | HAProxy resources | `{}` | | `haproxy.service.type` | HAProxy service type "ClusterIP" or "LoadBalancer" | `ClusterIP` | | `haproxy.service.annotations` | HAProxy service annotations | `{}` | +| `haproxy.hapreadport.enable` | Enable a read only port for redis slaves | `false` | +| `haproxy.hapreadport.port` | Haproxy port for read only redis slaves | `6380` | | `haproxy.exporter.enabled`| Enable Prometheus metric scraping | `false` | | `haproxy.exporter.port` | Prometheus metric scraping port | `9101` | | `haproxy.init.resources` | Extra init resources | `{}` | diff --git a/stable/redis-ha/templates/redis-ha-configmap.yaml b/stable/redis-ha/templates/redis-ha-configmap.yaml index 47853abec433..e8b2762924fd 100644 --- a/stable/redis-ha/templates/redis-ha-configmap.yaml +++ b/stable/redis-ha/templates/redis-ha-configmap.yaml @@ -177,12 +177,18 @@ data: {{- end }} # decide redis backend to use - frontend ft_redis + #master + frontend ft_redis_master bind *:6379 - use_backend bk_redis - + use_backend bk_redis_master + {{ if .Values.haproxy.readOnly.enabled }} + #slave + frontend ft_redis_slave + bind *:6380 + use_backend bk_redis_slave + {{- end }} # Check all redis servers to see if they think they are master - backend bk_redis + backend bk_redis_master mode tcp option tcp-check tcp-check connect @@ -199,7 +205,26 @@ data: {{- range $i := until $replicas }} use-server R{{ $i }} if { srv_is_up(R{{ $i }}) } { nbsrv(check_if_redis_is_master_{{ $i }}) ge 2 } server R{{ $i }} {{ $fullName }}-announce-{{ $i }}:6379 check inter 1s fall 1 rise 1 + {{- end }} + {{ if .Values.haproxy.readOnly.enabled }} + backend bk_redis_slave + mode tcp + option tcp-check + tcp-check connect + {{- if .Values.auth }} + tcp-check send AUTH\ {{ .Values.redisPassword }}\r\n + tcp-check expect string +OK + {{- end }} + tcp-check send PING\r\n + tcp-check expect string +PONG + tcp-check send info\ replication\r\n + tcp-check expect string role:slave + tcp-check send QUIT\r\n + tcp-check expect string +OK + {{- range $i := until $replicas }} + server R{{ $i }} {{ $fullName }}-announce-{{ $i }}:6379 check inter 1s fall 1 rise 1 {{- end }} + {{- end }} {{- end }} {{- end }} haproxy_init.sh: | diff --git a/stable/redis-ha/templates/redis-haproxy-deployment.yaml b/stable/redis-ha/templates/redis-haproxy-deployment.yaml index fd708ae5308a..e071229358f3 100644 --- a/stable/redis-ha/templates/redis-haproxy-deployment.yaml +++ b/stable/redis-ha/templates/redis-haproxy-deployment.yaml @@ -78,6 +78,11 @@ spec: - name: redis containerPort: {{ default "6379" .Values.redis.port }} hostPort: 6379 + {{- if .Values.haproxy.readOnly.enabled }} + - name: readonlyport + containerPort: {{ default "6380" .Values.haproxy.readOnly.port }} + hostPort: 6380 + {{- end }} resources: {{ toYaml .Values.haproxy.resources | indent 10 }} volumeMounts: @@ -93,4 +98,4 @@ spec: emptyDir: {} - name: data emptyDir: {} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/stable/redis-ha/templates/redis-haproxy-service.yaml b/stable/redis-ha/templates/redis-haproxy-service.yaml index 77d3345b6980..0c5bc0a26cc3 100644 --- a/stable/redis-ha/templates/redis-haproxy-service.yaml +++ b/stable/redis-ha/templates/redis-haproxy-service.yaml @@ -16,6 +16,12 @@ spec: port: {{ .Values.redis.port }} protocol: TCP targetPort: redis +{{- if .Values.haproxy.readOnly.enabled }} + - name: haproxyreadonly + port: {{ .Values.haproxy.readOnly.port }} + protocol: TCP + targetPort: {{ .Values.haproxy.readOnly.port }} +{{- end }} {{- if .Values.exporter.enabled }} - name: exporter-port port: {{ .Values.haproxy.exporter.port }} @@ -25,4 +31,4 @@ spec: selector: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }}-haproxy -{{- end }} \ No newline at end of file +{{- end }} diff --git a/stable/redis-ha/values.yaml b/stable/redis-ha/values.yaml index 36c6916532c9..84bcdc98bc93 100644 --- a/stable/redis-ha/values.yaml +++ b/stable/redis-ha/values.yaml @@ -26,6 +26,10 @@ serviceAccount: ## ref: https://cbonte.github.io/haproxy-dconv/1.9/intro.html haproxy: enabled: false + # Enable if you want a dedicated port in haproxy for redis-slaves + readOnly: + enabled: false + port: 6380 replicas: 1 image: repository: haproxy @@ -91,6 +95,7 @@ redis: rdbcompression: "yes" rdbchecksum: "yes" + ## Custom redis.conf files used to override default settings. If this file is ## specified then the redis.config above will be ignored. # customConfig: |-