mirror of https://github.com/easzlab/kubeasz.git
update manifests:es-cluster/mysql-cluster
parent
72012371c3
commit
36af7dd7ed
|
@ -10,6 +10,10 @@ metadata:
|
||||||
name: {{ template "elasticsearch.client.fullname" . }}
|
name: {{ template "elasticsearch.client.fullname" . }}
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.client.replicas }}
|
replicas: {{ .Values.client.replicas }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ template "elasticsearch.name" . }}
|
||||||
|
component: "{{ .Values.client.name }}"
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
|
@ -61,7 +65,7 @@ spec:
|
||||||
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
||||||
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
||||||
- name: "sysctl"
|
- name: "sysctl"
|
||||||
image: "busybox"
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
imagePullPolicy: "Always"
|
imagePullPolicy: "Always"
|
||||||
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
|
@ -18,11 +18,9 @@ spec:
|
||||||
- name: http
|
- name: http
|
||||||
port: 9200
|
port: 9200
|
||||||
targetPort: 9200
|
targetPort: 9200
|
||||||
nodePort: 29200
|
|
||||||
- name: tcp
|
- name: tcp
|
||||||
port: 9300
|
port: 9300
|
||||||
targetPort: 9300
|
targetPort: 9300
|
||||||
nodePort: 29300
|
|
||||||
selector:
|
selector:
|
||||||
app: {{ template "elasticsearch.name" . }}
|
app: {{ template "elasticsearch.name" . }}
|
||||||
component: "{{ .Values.client.name }}"
|
component: "{{ .Values.client.name }}"
|
||||||
|
|
|
@ -11,6 +11,10 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
serviceName: {{ template "elasticsearch.data.fullname" . }}
|
serviceName: {{ template "elasticsearch.data.fullname" . }}
|
||||||
replicas: {{ .Values.data.replicas }}
|
replicas: {{ .Values.data.replicas }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ template "elasticsearch.name" . }}
|
||||||
|
component: "{{ .Values.data.name }}"
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
|
@ -62,7 +66,7 @@ spec:
|
||||||
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
||||||
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
||||||
- name: "sysctl"
|
- name: "sysctl"
|
||||||
image: "busybox"
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
imagePullPolicy: "Always"
|
imagePullPolicy: "Always"
|
||||||
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
|
@ -11,6 +11,10 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
serviceName: {{ template "elasticsearch.master.fullname" . }}
|
serviceName: {{ template "elasticsearch.master.fullname" . }}
|
||||||
replicas: {{ .Values.master.replicas }}
|
replicas: {{ .Values.master.replicas }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ template "elasticsearch.name" . }}
|
||||||
|
component: "{{ .Values.master.name }}"
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
|
@ -62,7 +66,7 @@ spec:
|
||||||
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
||||||
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
|
||||||
- name: "sysctl"
|
- name: "sysctl"
|
||||||
image: "busybox"
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
imagePullPolicy: "Always"
|
imagePullPolicy: "Always"
|
||||||
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
|
# https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: mysql
|
name: mysql
|
||||||
labels:
|
labels:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
app.kubernetes.io/name: mysql
|
||||||
data:
|
data:
|
||||||
master.cnf: |
|
primary.cnf: |
|
||||||
# Apply this config only on the master.
|
# Apply this config only on the primary.
|
||||||
[mysqld]
|
[mysqld]
|
||||||
log-bin
|
log-bin
|
||||||
slave.cnf: |
|
replica.cnf: |
|
||||||
# Apply this config only on slaves.
|
# Apply this config only on replicas.
|
||||||
[mysqld]
|
[mysqld]
|
||||||
super-read-only
|
super-read-only
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/
|
||||||
# Headless service for stable DNS entries of StatefulSet members.
|
# Headless service for stable DNS entries of StatefulSet members.
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
|
@ -5,6 +6,7 @@ metadata:
|
||||||
name: mysql
|
name: mysql
|
||||||
labels:
|
labels:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
app.kubernetes.io/name: mysql
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- name: mysql
|
- name: mysql
|
||||||
|
@ -14,17 +16,18 @@ spec:
|
||||||
app: mysql
|
app: mysql
|
||||||
---
|
---
|
||||||
# Client service for connecting to any MySQL instance for reads.
|
# Client service for connecting to any MySQL instance for reads.
|
||||||
# For writes, you must instead connect to the master: mysql-0.mysql.
|
# For writes, you must instead connect to the primary: mysql-0.mysql.
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: mysql-read
|
name: mysql-read
|
||||||
labels:
|
labels:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
app.kubernetes.io/name: mysql
|
||||||
|
readonly: "true"
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- name: mysql
|
- name: mysql
|
||||||
port: 3306
|
port: 3306
|
||||||
selector:
|
selector:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -6,12 +7,14 @@ spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
app.kubernetes.io/name: mysql
|
||||||
serviceName: mysql
|
serviceName: mysql
|
||||||
replicas: 2
|
replicas: 2
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: mysql
|
app: mysql
|
||||||
|
app.kubernetes.io/name: mysql
|
||||||
spec:
|
spec:
|
||||||
initContainers:
|
initContainers:
|
||||||
- name: init-mysql
|
- name: init-mysql
|
||||||
|
@ -22,16 +25,16 @@ spec:
|
||||||
- |
|
- |
|
||||||
set -ex
|
set -ex
|
||||||
# Generate mysql server-id from pod ordinal index.
|
# Generate mysql server-id from pod ordinal index.
|
||||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
[[ $HOSTNAME =~ -([0-9]+)$ ]] || exit 1
|
||||||
ordinal=${BASH_REMATCH[1]}
|
ordinal=${BASH_REMATCH[1]}
|
||||||
echo [mysqld] > /mnt/conf.d/server-id.cnf
|
echo [mysqld] > /mnt/conf.d/server-id.cnf
|
||||||
# Add an offset to avoid reserved server-id=0 value.
|
# Add an offset to avoid reserved server-id=0 value.
|
||||||
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
|
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
|
||||||
# Copy appropriate conf.d files from config-map to emptyDir.
|
# Copy appropriate conf.d files from config-map to emptyDir.
|
||||||
if [[ $ordinal -eq 0 ]]; then
|
if [[ $ordinal -eq 0 ]]; then
|
||||||
cp /mnt/config-map/master.cnf /mnt/conf.d/
|
cp /mnt/config-map/primary.cnf /mnt/conf.d/
|
||||||
else
|
else
|
||||||
cp /mnt/config-map/slave.cnf /mnt/conf.d/
|
cp /mnt/config-map/replica.cnf /mnt/conf.d/
|
||||||
fi
|
fi
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: conf
|
- name: conf
|
||||||
|
@ -48,7 +51,7 @@ spec:
|
||||||
set -ex
|
set -ex
|
||||||
# Skip the clone if data already exists.
|
# Skip the clone if data already exists.
|
||||||
[[ -d /var/lib/mysql/mysql ]] && exit 0
|
[[ -d /var/lib/mysql/mysql ]] && exit 0
|
||||||
# Skip the clone on master (ordinal index 0).
|
# Skip the clone on primary (ordinal index 0).
|
||||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
||||||
ordinal=${BASH_REMATCH[1]}
|
ordinal=${BASH_REMATCH[1]}
|
||||||
[[ $ordinal -eq 0 ]] && exit 0
|
[[ $ordinal -eq 0 ]] && exit 0
|
||||||
|
@ -106,36 +109,39 @@ spec:
|
||||||
- |
|
- |
|
||||||
set -ex
|
set -ex
|
||||||
cd /var/lib/mysql
|
cd /var/lib/mysql
|
||||||
|
|
||||||
# Determine binlog position of cloned data, if any.
|
# Determine binlog position of cloned data, if any.
|
||||||
if [[ -f xtrabackup_slave_info ]]; then
|
if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then
|
||||||
# XtraBackup already generated a partial "CHANGE MASTER TO" query
|
# XtraBackup already generated a partial "CHANGE MASTER TO" query
|
||||||
# because we're cloning from an existing slave.
|
# because we're cloning from an existing replica. (Need to remove the tailing semicolon!)
|
||||||
mv xtrabackup_slave_info change_master_to.sql.in
|
cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in
|
||||||
# Ignore xtrabackup_binlog_info in this case (it's useless).
|
# Ignore xtrabackup_binlog_info in this case (it's useless).
|
||||||
rm -f xtrabackup_binlog_info
|
rm -f xtrabackup_slave_info xtrabackup_binlog_info
|
||||||
elif [[ -f xtrabackup_binlog_info ]]; then
|
elif [[ -f xtrabackup_binlog_info ]]; then
|
||||||
# We're cloning directly from master. Parse binlog position.
|
# We're cloning directly from primary. Parse binlog position.
|
||||||
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
|
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
|
||||||
rm xtrabackup_binlog_info
|
rm -f xtrabackup_binlog_info xtrabackup_slave_info
|
||||||
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
|
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
|
||||||
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
|
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if we need to complete a clone by starting replication.
|
# Check if we need to complete a clone by starting replication.
|
||||||
if [[ -f change_master_to.sql.in ]]; then
|
if [[ -f change_master_to.sql.in ]]; then
|
||||||
echo "Waiting for mysqld to be ready (accepting connections)"
|
echo "Waiting for mysqld to be ready (accepting connections)"
|
||||||
until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
|
until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
|
||||||
|
|
||||||
echo "Initializing replication from clone position"
|
echo "Initializing replication from clone position"
|
||||||
|
mysql -h 127.0.0.1 \
|
||||||
|
-e "$(<change_master_to.sql.in), \
|
||||||
|
MASTER_HOST='mysql-0.mysql', \
|
||||||
|
MASTER_USER='root', \
|
||||||
|
MASTER_PASSWORD='', \
|
||||||
|
MASTER_CONNECT_RETRY=10; \
|
||||||
|
START SLAVE;" || exit 1
|
||||||
# In case of container restart, attempt this at-most-once.
|
# In case of container restart, attempt this at-most-once.
|
||||||
mv change_master_to.sql.in change_master_to.sql.orig
|
mv change_master_to.sql.in change_master_to.sql.orig
|
||||||
mysql -h 127.0.0.1 <<EOF
|
|
||||||
$(<change_master_to.sql.orig),
|
|
||||||
MASTER_HOST='mysql-0.mysql',
|
|
||||||
MASTER_USER='root',
|
|
||||||
MASTER_PASSWORD='',
|
|
||||||
MASTER_CONNECT_RETRY=10;
|
|
||||||
START SLAVE;
|
|
||||||
EOF
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start a server to send backups when requested by peers.
|
# Start a server to send backups when requested by peers.
|
||||||
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
|
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
|
||||||
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
|
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
|
||||||
|
@ -160,7 +166,7 @@ spec:
|
||||||
name: data
|
name: data
|
||||||
spec:
|
spec:
|
||||||
accessModes: ["ReadWriteOnce"]
|
accessModes: ["ReadWriteOnce"]
|
||||||
storageClassName: "nfs-db"
|
storageClassName: "local-path"
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 5Gi
|
storage: 10Gi
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mycli
|
||||||
|
name: mysql-test-client
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mycli
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mycli
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: mycli
|
||||||
|
image: mysql:5.7
|
||||||
|
command:
|
||||||
|
- tail
|
||||||
|
- "-f"
|
||||||
|
- "/dev/null"
|
||||||
|
env:
|
||||||
|
- name: TZ
|
||||||
|
value: "Asia/Shanghai"
|
||||||
|
- name: LANG
|
||||||
|
value: "C.UTF-8"
|
Loading…
Reference in New Issue