summaryrefslogtreecommitdiffstats
path: root/kubernetes/common/mariadb-galera/resources
diff options
context:
space:
mode:
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>2020-11-27 11:07:42 +0100
committerSylvain Desbureaux <sylvain.desbureaux@orange.com>2020-12-14 17:28:07 +0100
commit93a5b49185695a7960ada82f5899265b5bc2e504 (patch)
treeaa6e43614e023008d8ca24f16468d69ca765319d /kubernetes/common/mariadb-galera/resources
parent92abd28e06b8221e8ff3f0785c9702376010ad94 (diff)
[COMMON][MARIADB] Upgrade Mariadb DB galera version
Mariadb DB Galera containers version is outdated and unmaintained. We need them to move to a new image provider. As new image provider is not compatible with our old templates, we also update the templates (by reworking bitnami mariadb-galera chart). An update of global mariadb image is also done in order to match mariadb galera version. Issue-ID: OOM-1720 Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com> Change-Id: Ib9976227759e90022183d4f37fc655143be4d6ac
Diffstat (limited to 'kubernetes/common/mariadb-galera/resources')
-rwxr-xr-xkubernetes/common/mariadb-galera/resources/config/configure-mysql.sh92
-rw-r--r--kubernetes/common/mariadb-galera/resources/create-deployment.yml50
-rw-r--r--kubernetes/common/mariadb-galera/resources/post-upgrade-script.sh142
-rw-r--r--kubernetes/common/mariadb-galera/resources/upgrade-scripts.sh101
4 files changed, 0 insertions, 385 deletions
diff --git a/kubernetes/common/mariadb-galera/resources/config/configure-mysql.sh b/kubernetes/common/mariadb-galera/resources/config/configure-mysql.sh
deleted file mode 100755
index b354efe86c..0000000000
--- a/kubernetes/common/mariadb-galera/resources/config/configure-mysql.sh
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/bin/bash
-{{/*
-#
-# Adfinis SyGroup AG
-# openshift-mariadb-galera: mysql setup script
-#
-*/}}
-
-set -eox pipefail
-
-echo 'Running mysql_install_db ...'
-mysql_install_db --datadir=/var/lib/mysql
-echo 'Finished mysql_install_db'
-
-mysqld --skip-networking --socket=/var/lib/mysql/mysql-init.sock --wsrep_on=OFF &
-pid="$!"
-
-mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/lib/mysql/mysql-init.sock )
-
-for i in {30..0}; do
- if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
- break
- fi
- echo 'MySQL init process in progress...'
- sleep 1
-done
-if [ "$i" = 0 ]; then
- echo >&2 'MySQL init process failed.'
- exit 1
-fi
-
-if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
- # sed is for https://bugs.mysql.com/bug.php?id=20545
- mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
-fi
-
-prepare_password()
-{
- echo "$1" | sed -e "s/'/\\\\'/g; s/\"/\\\\\"/g"
-}
-
-mysql_root_password=`prepare_password $MYSQL_ROOT_PASSWORD`
-# add MariaDB root user
-"${mysql[@]}" <<-EOSQL
--- What's done in this file shouldn't be replicated
--- or products like mysql-fabric won't work
-SET @@SESSION.SQL_LOG_BIN=0;
-
-DELETE FROM mysql.user ;
-CREATE USER 'root'@'%' IDENTIFIED BY '${mysql_root_password}' ;
-GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
-DROP DATABASE IF EXISTS test ;
-FLUSH PRIVILEGES ;
-EOSQL
-
-# add root password for subsequent calls to mysql
-if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
- mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
-fi
-
-# add users require for Galera
-# TODO: make them somehow configurable
-"${mysql[@]}" <<-EOSQL
-CREATE USER 'xtrabackup_sst'@'localhost' IDENTIFIED BY 'xtrabackup_sst' ;
-GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'xtrabackup_sst'@'localhost' ;
-CREATE USER 'readinessProbe'@'localhost' IDENTIFIED BY 'readinessProbe';
-EOSQL
-
-if [ "$MYSQL_DATABASE" ]; then
- echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
- mysql+=( "$MYSQL_DATABASE" )
-fi
-
-if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
- mysql_password=`prepare_password $MYSQL_PASSWORD`
- echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$mysql_password' ;" | "${mysql[@]}"
-
- if [ "$MYSQL_DATABASE" ]; then
- echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}"
- fi
-
- echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
-fi
-
-if ! kill -s TERM "$pid" || ! wait "$pid"; then
- echo >&2 'MySQL init process failed.'
- exit 1
-fi
-
-echo
-echo 'MySQL init process done. Ready for start up.'
-echo
diff --git a/kubernetes/common/mariadb-galera/resources/create-deployment.yml b/kubernetes/common/mariadb-galera/resources/create-deployment.yml
deleted file mode 100644
index 0f6bb5929e..0000000000
--- a/kubernetes/common/mariadb-galera/resources/create-deployment.yml
+++ /dev/null
@@ -1,50 +0,0 @@
-apiVersion: apps/v1
-kind: Deployment
-metadata: {{- include "common.resourceMetadata" (dict "suffix" "upgrade-deployment" "dot" .) | nindent 4 }}
-spec:
- replicas: 1
- selector:
- matchLabels:
- app: {{ include "common.fullname" . }}
- template:
- metadata:
- labels:
- app: {{ include "common.fullname" . }}
- spec:
- containers:
- - name: {{ include "common.name" . }}
- image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
- ports:
- - containerPort: {{ .Values.service.internalPort }}
- name: {{ .Values.service.portName }}
- - containerPort: {{ .Values.service.sstPort }}
- name: {{ .Values.service.sstPortName }}
- - containerPort: {{ .Values.service.replicationPort }}
- name: {{ .Values.service.replicationName }}
- - containerPort: {{ .Values.service.istPort }}
- name: {{ .Values.service.istPortName }}
- env:
- - name: POD_NAMESPACE
- valueFrom:
- fieldRef:
- apiVersion: v1
- fieldPath: metadata.namespace
- - name: MYSQL_USER
- valueFrom:
- secretKeyRef:
- key: login
- name: {{ include "common.fullname" . }}-temp-upgrade-usercred
- - name: MYSQL_PASSWORD
- valueFrom:
- secretKeyRef:
- key: password
- name: {{ include "common.fullname" . }}-temp-upgrade-usercred
- - name: MYSQL_DATABASE
- value: {{ default "" .Values.config.mysqlDatabase | quote }}
- - name: MYSQL_ROOT_PASSWORD
- valueFrom:
- secretKeyRef:
- key: password
- name: {{ include "common.fullname" . }}-temp-upgrade-root
- subdomain: {{ .Values.service.name }}
- hostname: {{ .Values.nameOverride }}-upgrade-deployment
diff --git a/kubernetes/common/mariadb-galera/resources/post-upgrade-script.sh b/kubernetes/common/mariadb-galera/resources/post-upgrade-script.sh
deleted file mode 100644
index ec09df3a86..0000000000
--- a/kubernetes/common/mariadb-galera/resources/post-upgrade-script.sh
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/bin/bash
-
-TEMP_POD=$(kubectl get pod -n $NAMESPACE_ENV --selector \
- app='{{ include "common.fullname" . }}' -o \
- jsonpath='{.items[?(@.metadata.ownerReferences[].kind=="ReplicaSet")].metadata.name}')
-
-tmp_MYSQL_PASSWORD=$(echo -n $(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv \
- MYSQL_PASSWORD) | base64)
-
-tmp_ROOT_PASSWORD=$(echo -n $(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv \
- MYSQL_ROOT_PASSWORD) | base64)
-
-FLAG_EX_ROOT_SEC='{{ include "common.secret.getSecretNameFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .)) }}'
-
-FLAG_EX_SEC='{{ include "common.secret.getSecretNameFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .)) }}'
-
-kubectl patch secret $FLAG_EX_ROOT_SEC -p \
- '{"data":{"password":"'"$tmp_ROOT_PASSWORD"'"}}'
-
-kubectl patch secret $FLAG_EX_SEC -p \
- '{"data":{"password":"'"$tmp_MYSQL_PASSWORD"'"}}'
-
-MYSQL_USER=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv MYSQL_USER)
-
-MYSQL_PASSWORD=$(echo -n $(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv MYSQL_PASSWORD))
-
-MYSQL_ROOT_PASSWORD=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- printenv MYSQL_ROOT_PASSWORD)
-
-CURRENT_STS_REPLICA=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
-
-DEPLOYMENT_REPLICA=$(kubectl get deployment -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }}-upgrade-deployment -o \
- jsonpath='{.status.replicas}')
-
-if [[ $CURRENT_STS_REPLICA == "0" ]]
-then
- echo "Seems there was no upgrade of cluster and we will scale up cluster replicas back to $REPLICA_COUNT now"
- kubectl scale statefulsets {{ include "common.fullname" . }} --replicas=$REPLICA_COUNT
-fi
-
-MY_REPLICA_NUMBER=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
-
-while [[ ! $MY_REPLICA_NUMBER == $REPLICA_COUNT ]]
-do
- echo "The cluster is not scaled up to $REPLICA_COUNT yet. Please wait ..."
- MY_REPLICA_NUMBER=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
- echo "The current status of the cluster is $MY_REPLICA_NUMBER"
- sleep 2
- if [[ $MY_REPLICA_NUMBER == $REPLICA_COUNT ]]
- then
- break
- fi
-done
-
-CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" | \
- awk '{print $2}')
-
-CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
-
-while [[ ! $CLUSTER_NO == $((REPLICA_COUNT+DEPLOYMENT_REPLICA)) ]] \
- || [[ ! $CLUSTER_STATE == "Synced" ]]
-do
- echo "$CLUSTER_NO and $CLUSTER_STATE"
- CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" \
- | awk '{print $2}')
- CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
- sleep 2
- if [[ $CLUSTER_NO == $((REPLICA_COUNT+DEPLOYMENT_REPLICA)) ]] \
- && [[ $CLUSTER_STATE == "Synced" ]]
- then
- echo "The cluster has $CLUSTER_NO members and $CLUSTER_STATE state."
- break
- fi
-done
-
-MYSQL_STATUS=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- mysqladmin \
- -uroot -p$MYSQL_ROOT_PASSWORD ping)
-
-while [[ ! $MYSQL_STATUS == "mysqld is alive" ]]
-do
- echo "Mariadb deployment is not ready yet."
- sleep 2
- MYSQL_STATUS=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- mysqladmin \
- -uroot -p$MYSQL_ROOT_PASSWORD ping)
- if [[ $MYSQL_STATUS == "mysqld is alive" ]]
- then
- echo "Mariadb deployment is ready and cluster size is $CLUSTER_NO"
- break
- fi
-done
-
-echo "Deleting upgrade deployment now"
-
-kubectl delete deployment -n $NAMESPACE_ENV {{ include "common.fullname" . }}-upgrade-deployment
-kubectl delete secret -n $NAMESPACE_ENV {{ include "common.fullname" . }}-temp-upgrade-root
-kubectl delete secret -n $NAMESPACE_ENV {{ include "common.fullname" . }}-temp-upgrade-usercred
-
-CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" | \
- awk '{print $2}')
-
-CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
-
-while [[ ! $CLUSTER_NO == $REPLICA_COUNT ]] \
- || [[ ! $CLUSTER_STATE == "Synced" ]]
-do
- echo "$CLUSTER_NO and $CLUSTER_STATE"
- CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" \
- | awk '{print $2}')
- CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV {{ include "common.fullname" . }}-0 -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
- sleep 2
- if [[ $CLUSTER_NO == $REPLICA_COUNT ]] \
- && [[ $CLUSTER_STATE == "Synced" ]]
- then
- echo "The cluster has $CLUSTER_NO members and $CLUSTER_STATE state."
- break
- fi
-done
-
-echo "The cluster upgrade is finished now"
diff --git a/kubernetes/common/mariadb-galera/resources/upgrade-scripts.sh b/kubernetes/common/mariadb-galera/resources/upgrade-scripts.sh
deleted file mode 100644
index ff44606e23..0000000000
--- a/kubernetes/common/mariadb-galera/resources/upgrade-scripts.sh
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-MYSQL_USER=$(kubectl exec -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }}-0 -- printenv MYSQL_USER)
-
-MYSQL_PASSWORD=$(kubectl exec -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }}-0 -- printenv MYSQL_PASSWORD)
-
-MYSQL_ROOT_PASSWORD=$(kubectl exec -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }}-0 -- printenv MYSQL_ROOT_PASSWORD)
-
-kubectl create secret generic \
- '{{ include "common.fullname" . }}'-temp-upgrade-root \
- --from-literal=password=$MYSQL_ROOT_PASSWORD
-
-kubectl create secret generic \
- '{{ include "common.fullname" . }}'-temp-upgrade-usercred \
- --from-literal=login=$MYSQL_USER --from-literal=password=$MYSQL_PASSWORD
-
-kubectl create -f /upgrade/create-deployment.yml
-
-TEMP_POD=$(kubectl get pod -n $NAMESPACE_ENV --selector \
- app='{{ include "common.fullname" . }}' -o \
- jsonpath='{.items[?(@.metadata.ownerReferences[].kind=="ReplicaSet")].metadata.name}')
-
-CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" | \
- awk '{print $2}')
-
-CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- \
- mysql --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
-
-STS_REPLICA=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
-
-DEPLOYMENT_REPLICA=$(kubectl get deployment -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }}-upgrade-deployment -o \
- jsonpath='{.status.replicas}')
-
-while [[ ! $CLUSTER_NO == $((STS_REPLICA+DEPLOYMENT_REPLICA)) ]] \
- || [[ ! $CLUSTER_STATE == "Synced" ]]
-do
- echo "$CLUSTER_NO and $CLUSTER_STATE"
- CLUSTER_NO=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size';" \
- | awk '{print $2}')
- CLUSTER_STATE=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysql \
- --skip-column-names -h{{ $.Values.service.name }} -u$MYSQL_USER \
- -p$MYSQL_PASSWORD -e "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment';" \
- | awk '{print $2}')
- sleep 2
- if [[ $CLUSTER_NO == $((STS_REPLICA+DEPLOYMENT_REPLICA)) ]] \
- && [[ $CLUSTER_STATE == "Synced" ]]
- then
- echo "The cluster has $CLUSTER_NO members and $CLUSTER_STATE state."
- break
- fi
-done
-
-MYSQL_STATUS=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysqladmin \
- -uroot -p$MYSQL_ROOT_PASSWORD ping)
-
-while [[ ! $MYSQL_STATUS == "mysqld is alive" ]]
-do
- echo "Mariadb deployment is not ready yet."
- sleep 2
- MYSQL_STATUS=$(kubectl exec -n $NAMESPACE_ENV $TEMP_POD -- mysqladmin \
- -uroot -p$MYSQL_ROOT_PASSWORD ping)
- if [[ $MYSQL_STATUS == "mysqld is alive" ]]
- then
- echo "Mariadb deployment is ready."
- break
- fi
-done
-
-kubectl scale statefulsets {{ include "common.fullname" . }} --replicas=0
-MY_REPLICA_NUMBER=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
-echo "The the cluster has $MY_REPLICA_NUMBER replicas."
-
-while [[ ! $MY_REPLICA_NUMBER == "0" ]]
-do
- echo "The cluster is not scaled to 0 yet. Please wait ..."
- MY_REPLICA_NUMBER=$(kubectl get statefulsets -n $NAMESPACE_ENV \
- {{ include "common.fullname" . }} -o jsonpath='{.status.replicas}')
- echo "The current status of the cluster is $MY_REPLICA_NUMBER"
- sleep 2
- if [[ $MY_REPLICA_NUMBER == "0" ]]
- then
- break
- fi
-done
-
-for (( index=0; index<$STS_REPLICA; index+=1 ))
-do
- kubectl delete pvc \
- "{{ include "common.fullname" . }}-data-{{ include "common.fullname" . }}-$index"
-done