tot pujat
This commit is contained in:
168
exemples/mariadb-replication/complete-mariadb-replication.yaml
Normal file
168
exemples/mariadb-replication/complete-mariadb-replication.yaml
Normal file
@@ -0,0 +1,168 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: mariadb-pv-0
|
||||
spec:
|
||||
capacity:
|
||||
storage: 300M
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath:
|
||||
path: "/mnt/data/mariadb-0"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: mariadb-pv-1
|
||||
spec:
|
||||
capacity:
|
||||
storage: 300M
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath:
|
||||
path: "/mnt/data/mariadb-1"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: mariadb-pv-2
|
||||
spec:
|
||||
capacity:
|
||||
storage: 300M
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath:
|
||||
path: "/mnt/data/mariadb-2"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: mariadb-configmap
|
||||
data:
|
||||
primary.cnf: |
|
||||
[mariadb]
|
||||
log-bin # enable binary logging
|
||||
log-basename=my-mariadb # independent of hostname changes
|
||||
|
||||
replica.cnf: |
|
||||
[mariadb]
|
||||
log-basename=my-mariadb # independent of hostname changes
|
||||
|
||||
primary.sql: |
|
||||
CREATE USER 'repluser'@'%' IDENTIFIED BY 'replsecret';
|
||||
GRANT REPLICATION REPLICA ON *.* TO 'repluser'@'%';
|
||||
CREATE DATABASE primary_db;
|
||||
|
||||
secondary.sql: |
|
||||
CHANGE MASTER TO
|
||||
MASTER_HOST='mariadb-sts-0.mariadb-service.default.svc.cluster.local',
|
||||
MASTER_USER='repluser',
|
||||
MASTER_PASSWORD='replsecret',
|
||||
MASTER_CONNECT_RETRY=10;
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mariadb-secret
|
||||
type: Opaque
|
||||
data:
|
||||
mariadb-root-password: c2VjcmV0 # echo -n 'secret'|base64
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mariadb-service
|
||||
labels:
|
||||
app: mariadb
|
||||
spec:
|
||||
ports:
|
||||
- port: 3306
|
||||
name: mariadb-port
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: mariadb
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: mariadb-sts
|
||||
spec:
|
||||
serviceName: "mariadb-service"
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mariadb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mariadb
|
||||
spec:
|
||||
initContainers:
|
||||
- name: init-mariadb
|
||||
image: mariadb
|
||||
imagePullPolicy: Always
|
||||
command:
|
||||
- bash
|
||||
- "-c"
|
||||
- |
|
||||
set -ex
|
||||
echo 'Starting init-mariadb';
|
||||
ls /mnt/config-map
|
||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
||||
ordinal=${BASH_REMATCH[1]}
|
||||
if [[ $ordinal -eq 0 ]]; then
|
||||
cp /mnt/config-map/primary.cnf /etc/mysql/conf.d/server-id.cnf
|
||||
cp /mnt/config-map/primary.sql /docker-entrypoint-initdb.d
|
||||
else
|
||||
cp /mnt/config-map/replica.cnf /etc/mysql/conf.d/server-id.cnf
|
||||
cp /mnt/config-map/secondary.sql /docker-entrypoint-initdb.d
|
||||
fi
|
||||
echo server-id=$((3000 + $ordinal)) >> /etc/mysql/conf.d/server-id.cnf
|
||||
ls /etc/mysql/conf.d/
|
||||
cat /etc/mysql/conf.d/server-id.cnf
|
||||
volumeMounts:
|
||||
- name: mariadb-config-map
|
||||
mountPath: /mnt/config-map
|
||||
- name: mariadb-config
|
||||
mountPath: /etc/mysql/conf.d/
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
restartPolicy: Always
|
||||
containers:
|
||||
- name: mariadb
|
||||
image: mariadb
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
name: mariadb-port
|
||||
env:
|
||||
- name: MARIADB_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mariadb-secret
|
||||
key: mariadb-root-password
|
||||
- name: MYSQL_INITDB_SKIP_TZINFO
|
||||
value: "1"
|
||||
volumeMounts:
|
||||
- name: datadir
|
||||
mountPath: /var/lib/mysql/
|
||||
- name: mariadb-config
|
||||
mountPath: /etc/mysql/conf.d/
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
volumes:
|
||||
- name: mariadb-config-map
|
||||
configMap:
|
||||
name: mariadb-configmap
|
||||
- name: mariadb-config
|
||||
emptyDir: {}
|
||||
- name: initdb
|
||||
emptyDir: {}
|
||||
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: datadir
|
||||
spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
resources:
|
||||
requests:
|
||||
storage: 300M
|
||||
Reference in New Issue
Block a user