This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redis clusters for dshop backends (#4483)
* adds redis cluster for rinkeby backend * adds mainnet cluster
- Loading branch information
1 parent
e6134e8
commit a862c4e
Showing
9 changed files
with
352 additions
and
2 deletions.
There are no files selected for viewing
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
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
73 changes: 73 additions & 0 deletions
73
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-mainnet.configmap.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,73 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ template "dshopRedisMainnet.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-mainnet | ||
data: | ||
redis.conf: |+ | ||
dir /data/redis | ||
cluster-enabled yes | ||
cluster-require-full-coverage no | ||
cluster-node-timeout 15000 | ||
cluster-config-file nodes.conf | ||
cluster-migration-barrier 1 | ||
# Restoring with RDB with appendonly https://stackoverflow.com/a/23233940/402412 | ||
appendonly yes | ||
# Other cluster members need to be able to connect | ||
protected-mode no | ||
bootstrap-pod.sh: |+ | ||
#!/bin/sh | ||
set -e | ||
# Create the data dir | ||
mkdir -p /data/redis | ||
# Find which member of the Stateful Set this pod is running | ||
ORDINAL=$(hostname | rev | cut -d- -f1) | ||
# Only restore if the dump file exists and restore wasn't explicity disabled | ||
if [[ -z "$DISABLE_RESTORE" && -f /data/redis/restore.rdb ]]; then | ||
echo "Restore redis dump found. Restoring..." | ||
# move original data over if it exists | ||
[[ -f /data/redis/dump.rdb ]] && mv /data/redis/dump.rdb /data/redis/dump.rdb.backup | ||
[[ -f /data/redis/appendonly.aof ]] && mv /data/redis/appendonly.aof /data/redis/appendonly.aof.backup | ||
# Move restore dump to where it will be loaded | ||
mv /data/redis/restore.rdb /data/redis/dump.rdb | ||
fi | ||
# Launch a server instance so we can configure it | ||
redis-server /config/redis.conf & | ||
# TODO: Wait until redis-server process is ready | ||
sleep 1 | ||
if [ $ORDINAL = "0" ]; then | ||
echo "This is the MASTER node" | ||
# The first member of the cluster should control all slots initially | ||
redis-cli cluster addslots $(seq 0 16383) | ||
else | ||
echo "This is the SLAVE node. Master: $STS_NAME-0.$STS_NAME.$NAMESPACE.svc.cluster.local" | ||
# Other members of the cluster join as slaves | ||
MASTER_IP=$(echo "print inet_ntoa(scalar(gethostbyname('$STS_NAME-0.$STS_NAME.$NAMESPACE.svc.cluster.local')))" | perl -MSocket) | ||
redis-cli cluster meet $MASTER_IP 6379 | ||
sleep 1 | ||
# Become the slave of a random master node | ||
MASTER_ID=$(redis-cli --csv cluster slots | cut -d, -f 5 | sed -e 's/^"//' -e 's/"$//') | ||
redis-cli cluster replicate $MASTER_ID | ||
fi |
22 changes: 22 additions & 0 deletions
22
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-mainnet.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,22 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "dshopRedisMainnet.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-mainnet | ||
spec: | ||
clusterIP: None | ||
selector: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
ports: | ||
- name: redis | ||
port: 6379 | ||
- name: gossip | ||
port: 16379 |
75 changes: 75 additions & 0 deletions
75
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-mainnet.statefulset.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,75 @@ | ||
apiVersion: apps/v1 | ||
kind: StatefulSet | ||
metadata: | ||
name: {{ template "dshopRedisMainnet.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-mainnet | ||
spec: | ||
replicas: {{ default 2 .Values.dshopRedisMainnetReplicas }} | ||
selector: | ||
matchLabels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
serviceName: {{ template "dshopRedisMainnet.fullname" . }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
spec: | ||
initContainers: | ||
- name: configure-redis | ||
image: "{{ .Values.dshopRedisImage }}:{{ .Values.dshopRedisImageTag }}" | ||
command: ["/bin/bash", "/config/bootstrap-pod.sh"] | ||
env: | ||
- name: NAMESPACE | ||
value: experimental | ||
- name: STS_NAME | ||
value: {{ template "dshopRedisMainnet.fullname" . }} | ||
volumeMounts: | ||
- mountPath: /data | ||
name: {{ template "dshopRedisMainnet.fullname" . }}-redis | ||
- mountPath: /config | ||
name: config | ||
readOnly: false | ||
containers: | ||
- name: redis | ||
image: "{{ .Values.dshopRedisImage }}:{{ .Values.dshopRedisImageTag }}" | ||
command: ["redis-server", "/config/redis.conf"] | ||
volumeMounts: | ||
- mountPath: /data | ||
name: {{ template "dshopRedisMainnet.fullname" . }}-redis | ||
- mountPath: /config | ||
name: config | ||
readOnly: false | ||
port: | ||
- name: redis | ||
containerPort: 6379 | ||
- name: gossip | ||
containerPort: 16379 | ||
volumes: | ||
- name: config | ||
configMap: | ||
name: {{ template "dshopRedisMainnet.fullname" . }} | ||
items: | ||
- key: redis.conf | ||
path: redis.conf | ||
- key: bootstrap-pod.sh | ||
path: bootstrap-pod.sh | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: {{ template "dshopRedisMainnet.fullname" . }}-redis | ||
labels: | ||
app: {{ template "dshopRedisMainnet.fullname" . }} | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce # Read-write for a single node only | ||
storageClassName: "standard" | ||
resources: | ||
requests: | ||
storage: {{ default "8Gi" .Values.dshopRedisStorageSize }} |
73 changes: 73 additions & 0 deletions
73
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-rinkeby.configmap.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,73 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ template "dshopRedisRinkeby.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-rinkeby | ||
data: | ||
redis.conf: |+ | ||
dir /data/redis | ||
cluster-enabled yes | ||
cluster-require-full-coverage no | ||
cluster-node-timeout 15000 | ||
cluster-config-file nodes.conf | ||
cluster-migration-barrier 1 | ||
# Restoring with RDB with appendonly https://stackoverflow.com/a/23233940/402412 | ||
appendonly yes | ||
# Other cluster members need to be able to connect | ||
protected-mode no | ||
bootstrap-pod.sh: |+ | ||
#!/bin/sh | ||
set -e | ||
# Create the data dir | ||
mkdir -p /data/redis | ||
# Find which member of the Stateful Set this pod is running | ||
ORDINAL=$(hostname | rev | cut -d- -f1) | ||
# Only restore if the dump file exists and restore wasn't explicity disabled | ||
if [[ -z "$DISABLE_RESTORE" && -f /data/redis/restore.rdb ]]; then | ||
echo "Restore redis dump found. Restoring..." | ||
# move original data over if it exists | ||
[[ -f /data/redis/dump.rdb ]] && mv /data/redis/dump.rdb /data/redis/dump.rdb.backup | ||
[[ -f /data/redis/appendonly.aof ]] && mv /data/redis/appendonly.aof /data/redis/appendonly.aof.backup | ||
# Move restore dump to where it will be loaded | ||
mv /data/redis/restore.rdb /data/redis/dump.rdb | ||
fi | ||
# Launch a server instance so we can configure it | ||
redis-server /config/redis.conf & | ||
# TODO: Wait until redis-server process is ready | ||
sleep 1 | ||
if [ $ORDINAL = "0" ]; then | ||
echo "This is the MASTER node" | ||
# The first member of the cluster should control all slots initially | ||
redis-cli cluster addslots $(seq 0 16383) | ||
else | ||
echo "This is the SLAVE node. Master: $STS_NAME-0.$STS_NAME.$NAMESPACE.svc.cluster.local" | ||
# Other members of the cluster join as slaves | ||
MASTER_IP=$(echo "print inet_ntoa(scalar(gethostbyname('$STS_NAME-0.$STS_NAME.$NAMESPACE.svc.cluster.local')))" | perl -MSocket) | ||
redis-cli cluster meet $MASTER_IP 6379 | ||
sleep 1 | ||
# Become the slave of a random master node | ||
MASTER_ID=$(redis-cli --csv cluster slots | cut -d, -f 5 | sed -e 's/^"//' -e 's/"$//') | ||
redis-cli cluster replicate $MASTER_ID | ||
fi |
22 changes: 22 additions & 0 deletions
22
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-rinkeby.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,22 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "dshopRedisRinkeby.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-rinkeby | ||
spec: | ||
clusterIP: None | ||
selector: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
ports: | ||
- name: redis | ||
port: 6379 | ||
- name: gossip | ||
port: 16379 |
75 changes: 75 additions & 0 deletions
75
devops/kubernetes/charts/origin-experimental/templates/dshop-redis-rinkeby.statefulset.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,75 @@ | ||
apiVersion: apps/v1 | ||
kind: StatefulSet | ||
metadata: | ||
name: {{ template "dshopRedisRinkeby.fullname" . }} | ||
labels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
app.kubernetes.io/name: dshop | ||
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion }} | ||
app.kubernetes.io/component: backend | ||
app.kubernetes.io/part-of: dshop-backend-rinkeby | ||
spec: | ||
replicas: {{ default 2 .Values.dshopRedisRinkebyReplicas }} | ||
selector: | ||
matchLabels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
serviceName: {{ template "dshopRedisRinkeby.fullname" . }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
spec: | ||
initContainers: | ||
- name: configure-redis | ||
image: "{{ .Values.dshopRedisImage }}:{{ .Values.dshopRedisImageTag }}" | ||
command: ["/bin/bash", "/config/bootstrap-pod.sh"] | ||
env: | ||
- name: NAMESPACE | ||
value: experimental | ||
- name: STS_NAME | ||
value: {{ template "dshopRedisRinkeby.fullname" . }} | ||
volumeMounts: | ||
- mountPath: /data | ||
name: {{ template "dshopRedisRinkeby.fullname" . }}-redis | ||
- mountPath: /config | ||
name: config | ||
readOnly: false | ||
containers: | ||
- name: redis | ||
image: "{{ .Values.dshopRedisImage }}:{{ .Values.dshopRedisImageTag }}" | ||
command: ["redis-server", "/config/redis.conf"] | ||
volumeMounts: | ||
- mountPath: /data | ||
name: {{ template "dshopRedisRinkeby.fullname" . }}-redis | ||
- mountPath: /config | ||
name: config | ||
readOnly: false | ||
port: | ||
- name: redis | ||
containerPort: 6379 | ||
- name: gossip | ||
containerPort: 16379 | ||
volumes: | ||
- name: config | ||
configMap: | ||
name: {{ template "dshopRedisRinkeby.fullname" . }} | ||
items: | ||
- key: redis.conf | ||
path: redis.conf | ||
- key: bootstrap-pod.sh | ||
path: bootstrap-pod.sh | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: {{ template "dshopRedisRinkeby.fullname" . }}-redis | ||
labels: | ||
app: {{ template "dshopRedisRinkeby.fullname" . }} | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce # Read-write for a single node only | ||
storageClassName: "standard" | ||
resources: | ||
requests: | ||
storage: {{ default "8Gi" .Values.dshopRedisStorageSize }} |
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