forked from googleforgames/open-match
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-redis-failover.yaml
166 lines (158 loc) · 5.08 KB
/
01-redis-failover.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
apiVersion: v1
kind: Secret
metadata:
name: om-secret
type: Opaque
data:
# WARNING
# Redis-operator doesn't support the authentication yet:
# https://github.com/spotahome/redis-operator/issues/66
#
# So for Open Match components to work these keys must always be empty.
redis.user: |
redis.password: |
---
apiVersion: storage.spotahome.com/v1alpha2
kind: RedisFailover
metadata:
name: redisfailover
labels:
tier: storage
spec:
hardAntiAffinity: true # Optional. Value by default. If true, the pods will not be scheduled on the same node.
sentinel:
replicas: 3 # Optional. 3 by default, can be set higher.
resources: # Optional. If not set, it won't be defined on created resources.
requests:
cpu: 100m
limits:
memory: 100Mi
customConfig: [] # Optional. Empty by default.
redis:
replicas: 3 # Optional. 3 by default, can be set higher.
image: redis # Optional. "redis" by default.
version: 4.0.11-alpine # Optional. "3.2-alpine" by default.
resources: # Optional. If not set, it won't be defined on created resources
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 400m
memory: 500Mi
exporter: false # Optional. False by default. Adds a redis-exporter container to export metrics.
exporterImage: oliver006/redis_exporter # Optional. oliver006/redis_exporter by default.
exporterVersion: v0.11.3 # Optional. v0.11.3 by default.
disableExporterProbes: false # Optional. False by default. Disables the readiness and liveness probes for the exporter.
storage:
emptyDir: {} # Optional. emptyDir by default.
customConfig: [] # Optional. Empty by default.\
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-master-proxy-configmap
data:
haproxy.cfg: |
defaults REDIS
mode tcp
timeout connect 5s
timeout client 61s # should respect 'redis.pool.idleTimeout' from open-match config
timeout server 61s
global
stats socket ipv4@127.0.0.1:9999 level admin
stats timeout 2m
frontend fe_redis
bind *:17000 name redis
default_backend be_redis
backend be_redis
server redis-master-serv 127.0.0.1:6379
redis-master-finder.sh: |
#!/bin/sh
set -e
set -u
SENTINEL_HOST="rfs-redisfailover" # change this if RedisFailover name changes
LAST_MASTER_IP=""
LAST_MASTER_PORT=""
update_master_addr() {
# lookup current master address
local r="SENTINEL get-master-addr-by-name mymaster"
local r_out=$(echo $r | nc -q1 $SENTINEL_HOST 26379)
# parse output
local master_ip=$(echo "${r_out}" | tail -n+3 | head -n1 | tr -d '\r') # IP is on 3d line
local master_port=$(echo "${r_out}" | tail -n+5 | head -n1 | tr -d '\r') # 5th line is port number
# update HAProxy cfg if needed
if [ "$master_ip" != "$LAST_MASTER_IP" ] || [ "$master_port" != "$LAST_MASTER_PORT" ]; then
local s="set server be_redis/redis-master-serv addr ${master_ip} port ${master_port}"
echo $s | nc 127.0.0.1 9999 # haproxy is in the same pod
LAST_MASTER_IP=$master_ip
LAST_MASTER_PORT=$master_port
echo "New master address is ${LAST_MASTER_IP}:${LAST_MASTER_PORT}"
fi
}
while :; do update_master_addr; sleep 1; done
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: redis-master-proxy
labels:
app: openmatch
component: redis
tier: storage
spec:
replicas: 1
selector:
matchLabels:
app: openmatch
component: redis
tier: storage
template:
metadata:
labels:
app: openmatch
component: redis
tier: storage
spec:
volumes:
- name: configmap
configMap:
name: redis-master-proxy-configmap
defaultMode: 0700
containers:
- name: redis-master-haproxy
image: haproxy:1.8-alpine
ports:
- name: haproxy
containerPort: 17000
- name: haproxy-stats
containerPort: 9999
volumeMounts:
- name: configmap
mountPath: /usr/local/etc/haproxy/haproxy.cfg
subPath: haproxy.cfg
- name: redis-master-finder
image: subfuzion/netcat # alpine image with only netcat-openbsd installed
imagePullPolicy: Always
command: ["redis-master-finder.sh"]
volumeMounts:
- name: configmap
mountPath: /usr/local/bin/redis-master-finder.sh
subPath: redis-master-finder.sh
resources:
requests:
memory: 20Mi
cpu: 100m
---
kind: Service
apiVersion: v1
metadata:
name: redis
spec:
selector:
app: openmatch
component: redis
tier: storage
ports:
- protocol: TCP
port: 6379
targetPort: haproxy