This repository was archived by the owner on May 28, 2021. It is now read-only.
This repository was archived by the owner on May 28, 2021. It is now read-only.
Create initial DB and user #13
Open
Description
At the moment I'm using a helm chart to make a job that initialises the cluster once it's up. This feels like a bit of a hack:
apiVersion: batch/v1
kind: Job
metadata:
name: example-mysql-init
spec:
template:
metadata:
name: example-mysql-init
labels:
role: mysql-init
spec:
containers:
- name: init
image: mysql
command:
- "bash"
- "-c"
- |
set -ex
mysqladmin -h {{ .Release.Name }}-mysql --user=root --password=$DB_ROOT_PASSWD ping
mysql -h {{ .Release.Name }}-mysql --user=root --password=$DB_ROOT_PASSWD --batch --skip-column-names <<-EOF
create database if not exists $DB_DATABASE;
grant all privileges on $DB_DATABASE.* to '$DB_USER'@'%' identified by '$DB_PASSWD';
flush privileges;
EOF
env:
- name: DB_PASSWD
valueFrom:
secretKeyRef:
name: cluster-mysql
key: mysql-password
- name: DB_ROOT_PASSWD
valueFrom:
secretKeyRef:
name: cluster-mysql-root-password
key: password
- name: DB_HOST
value: cluster-mysql
- name: DB_DATABASE
value: my_db_name
- name: DB_USER
value: my_db_user
restartPolicy: Never
# the default of 6 might not be enough
backoffLimit: 600