環境變數:
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}