以helm在k8s上部署mariaDB

環境變數:

PASSWORD="1234567890"
NAME="db"
SERVICE="${NAME}-mariadb"
NAMESPACE="default"

儲存裝置為nfs

helm install \
  --namespace ${NAMESPACE} \
  --name ${NAME} stable/mariadb \
  --set slave.replicas=3 \
  --set rootUser.password=replicator \
  --set replication.user="${PASSWORD}" \
  --set replication.password="${PASSWORD}" \
  --set master.persistence.storageClass=managed-nfs-storage \
  --set slave.persistence.storageClass=managed-nfs-storage

參數參考

允許root@%登入(注意:密碼不能隨意變動)

kubectl exec -it -n ${NAMESPACE} ${SERVICE}-master-0 -- mysql -uroot -p${PASSWORD} -e "grant all privileges on *.* to 'root' @'%' identified by '${PASSWORD}'; FLUSH PRIVILEGES;"

變更密碼正確方式:

NEW_PASSWORD="0987654321"
PASSWORD=$(kubectl get secret -n ${NAMESPACE} ${SERVICE} -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
echo "Password: ${PASSWORD}"
helm upgrade ${NAME} stable/mariadb --set rootUser.password=${NEW_PASSWORD}

以docker快速建立mysql測試環境

剛剛因為要測試mysql跟mariaDB的語法是否有不同
因此用下列語法快速建立mysql來進行測試

#建立mysql server
docker run \
  --name some-mysql \
  -e MYSQL_ROOT_PASSWORD=abcdefg \
  -d mysql:5.7
sleep 10

#建立mysql client
docker run \
  -it \
  --rm \
  --link some-mysql:mysqlA \
  mysql sh -c 'exec mysql -h mysqlA -uroot -pabcdefg'

SQL測試語法

create database TEST1;
use TEST1;
CREATE TABLE `test` (
  `id` int(11) NOT NULL,
  `geo` point DEFAULT NULL
);
INSERT INTO `test`(`id`, `geo`) VALUES (1,ST_GEOMFROMTEXT('POINT(121 23)',4326));
select * from `test` where 1;