-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis-statefulset.yaml
99 lines (99 loc) · 2.27 KB
/
redis-statefulset.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
selector:
matchLabels:
app: redis
serviceName: redis
replicas: 3
template:
metadata:
labels:
app: redis
spec:
initContainers:
- name: init-redis
image: library/redis:3.2
command:
- bash
- "-c"
- |
set -ex
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
[[ -f /mnt/conf/redis.conf ]] && exit 0
ordinal=${BASH_REMATCH[1]}
# Copy appropriate conf.d files from config-map to emptyDir.
cp /mnt/config-map/shared.conf /mnt/conf/redis.conf
# ordinal 0 is the first host
if [[ $ordinal -eq 0 ]]; then
cat /mnt/config-map/master.conf >> /mnt/conf/redis.conf
else
cat /mnt/config-map/slave.conf >> /mnt/conf/redis.conf
fi
volumeMounts:
- name: conf
mountPath: /mnt/conf
- name: config-map
mountPath: /mnt/config-map
- name: data
mountPath: /data
containers:
- name: redis
command: ["redis-server", "/etc/redis/redis.conf"]
image: library/redis:3.2
ports:
- name: redis
containerPort: 6379
volumeMounts:
- name: data
mountPath: /data
- name: conf
mountPath: /etc/redis
resources:
requests:
cpu: 100m
memory: 256Mi
readinessProbe:
exec:
command:
- sh
- -c
- "/usr/local/bin/redis-cli -h $(hostname) ping"
initialDelaySeconds: 15
timeoutSeconds: 5
volumes:
- name: config-map
configMap:
name: redis
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 500Mi
- metadata:
name: conf
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Mi
---
# Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: redis
spec:
ports:
- name: redis
port: 6379
clusterIP: None
selector:
app: redis