-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis.yaml
76 lines (76 loc) · 2.3 KB
/
redis.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
namespace: redis
spec:
serviceName: redis
replicas: 3
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
initContainers:
- name: config
image: redis:7.0.0-alpine
command: [ "sh", "-c" ]
args:
- |
echo "Copying configuration file"
cp /tmp/redis/redis.conf /etc/redis/redis.conf
if [ "$(redis-cli -h sentinel -p 5000 ping)" != "PONG" ]; then
echo "Sentinel not found to get the master info, defaulting to redis-0"
if [ "$(hostname)" == "redis-0" ]; then
echo "This is redis-0, No need to update config."
else
echo "This is not redis-0, Updating redis.conf. finding master FQDN"
MASTER_FDQN=`hostname -f | sed -e 's/redis-[0-9]\./redis-0./'`
echo "REPLICAOF $MASTER_FDQN 6379" >> /etc/redis/redis.conf
fi
else
echo "Sentinel found, finding master"
MASTER="$(redis-cli -h sentinel -p 5000 sentinel get-master-addr-by-name mymaster | grep -E '(^redis-\d{1,})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})')"
echo "Master got: $MASTER, updating this in redis.conf"
echo "REPLICAOF $MASTER 6379" >> /etc/redis/redis.conf
fi
volumeMounts:
- name: redis-config
mountPath: /etc/redis/
- name: config
mountPath: /tmp/redis/
containers:
- name: redis
image: redis:7.0.0-alpine
command: ["redis-server"]
args: ["/etc/redis/redis.conf"]
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: data
mountPath: /data
- name: redis-config
mountPath: /etc/redis/
- name: config-acl
mountPath: /conf/acl/
volumes:
- name: redis-config
emptyDir: {}
- name: config
configMap:
name: redis-config
- name: config-acl
configMap:
name: redis-acl
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Mi