Files
trade-deploy/kustomize/base/dlob/redis.yaml

80 lines
2.4 KiB
YAML

apiVersion: v1
kind: Service
metadata:
name: dlob-redis
annotations:
argocd.argoproj.io/sync-wave: "3"
spec:
selector:
app.kubernetes.io/name: dlob-redis
ports:
- name: redis
port: 6379
targetPort: redis
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dlob-redis
annotations:
argocd.argoproj.io/sync-wave: "3"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: dlob-redis
template:
metadata:
labels:
app.kubernetes.io/name: dlob-redis
spec:
containers:
- name: redis
image: redis:7-alpine
imagePullPolicy: IfNotPresent
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
ports:
- name: redis
containerPort: 6379
# DLOB redis client uses ioredis Cluster when RUNNING_LOCAL=true and LOCAL_CACHE=true.
# We run a single-node Redis Cluster (no TLS) and assign all slots on startup.
command: ["/bin/sh", "-lc"]
args:
- |
exec redis-server \
--save "" \
--appendonly no \
--protected-mode no \
--bind 0.0.0.0 \
--cluster-enabled yes \
--cluster-config-file /data/nodes.conf \
--cluster-node-timeout 5000 \
--cluster-require-full-coverage no \
--cluster-announce-ip "${POD_IP}" \
--cluster-announce-port 6379 \
--cluster-announce-bus-port 16379
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -lc
- |
set -e
for i in $(seq 1 60); do
redis-cli -h 127.0.0.1 -p 6379 ping >/dev/null 2>&1 && break
sleep 1
done
# If cluster is already initialized, do nothing.
if redis-cli -h 127.0.0.1 -p 6379 cluster info 2>/dev/null | grep -q 'cluster_slots_assigned:16384'; then
exit 0
fi
# Redis 7+ supports CLUSTER ADDSLOTSRANGE.
redis-cli -h 127.0.0.1 -p 6379 cluster addslotsrange 0 16383 || true