-
Notifications
You must be signed in to change notification settings - Fork 12
/
galera-cluster.yaml
186 lines (183 loc) · 4.84 KB
/
galera-cluster.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# A headless service to create DNS records
apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
name: galera-db
labels:
app: mysql-db
spec:
ports:
- port: 3306
name: mysql-db
# *.galear.default.svc.cluster.local
clusterIP: None
selector:
app: mysql-db
---
apiVersion: v1
kind: Secret
metadata:
name: mysql-db
type: Opaque
data:
# Root password (base64): 123456 # echo -n '123456' | base64
password: MTIzNDU2
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config-voldb
data:
galera.cnf: |
[mysqld]
user = mysql
bind-address = 0.0.0.0
wsrep_provider = /usr/lib/galera/libgalera_smm.so
# TODO: is rsync the best option?
wsrep_sst_method = rsync
default_storage_engine = innodb
binlog_format = ROW
innodb_autoinc_lock_mode = 2
innodb_file_per_table
max_connections = 2500
key-buffer-size = 32M
max-allowed-packet = 16M
max-connect-errors = 1000000
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 1
query-cache-size = 1000M
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 50
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 1G
# By default every node is standalone
wsrep_cluster_address=gcomm://
wsrep_cluster_name=galera
wsrep_node_address=127.0.0.1
# TODO: Enable use privileges. This doesn't work
# on mysql restart, for some reason after the SST
# permissions are not setup correctly.
mariadb.cnf: |
[client]
default-character-set = utf8
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
# InnoDB tuning
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql-db
spec:
serviceName: "galera-db"
replicas: 3
selector:
matchLabels:
app: mysql-db
template:
metadata:
labels:
app: mysql-db
spec:
nodeSelector: # kubectl label nodes kube-2 nodedb=mysql
nodedb: mysql # kubectl get nodes --show-labels
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- mysql-db
topologyKey: "kubernetes.io/hostname"
initContainers:
- name: install
image: dome/galera-install
imagePullPolicy: Always
args:
- "--work-dir=/work-dir"
volumeMounts:
- name: workdir
mountPath: "/work-dir"
- name: config
mountPath: "/etc/mysql"
- name: tmp-config
mountPath: /tmp
- name: bootstrap
image: debian:jessie
command:
- "/work-dir/peer-finder"
args:
- -on-start="/work-dir/on-start.sh"
- "-service=galera-db"
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
volumeMounts:
- name: workdir
mountPath: "/work-dir"
- name: config
mountPath: "/etc/mysql"
containers:
- name: mysql
image: k8s.gcr.io/mysql-galera:e2e
ports:
- containerPort: 3306
name: mysql
- containerPort: 4444
name: sst
- containerPort: 4567
name: replication
- containerPort: 4568
name: ist
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-db
key: password
args:
- --defaults-file=/etc/mysql/my-galera.cnf
- --user=root
readinessProbe:
exec:
command: ["bash", "-c", "mysql -uroot -p\"${MYSQL_ROOT_PASSWORD}\" -e 'show databases;'"]
initialDelaySeconds: 20
timeoutSeconds: 5
successThreshold: 2
volumeMounts:
- name: datadir
mountPath: /var/lib/
- name: config
mountPath: /etc/mysql
volumes:
- name: datadir
hostPath:
path: /data/galera
type: Directory
- name: config
emptyDir: {}
- name: workdir
emptyDir: {}
- name: tmp-config
configMap:
name: mysql-config-voldb
items:
- path: "my-galera.cnf"
key: galera.cnf
- path: "mariadb.cnf"
key: mariadb.cnf