Pasang "buat skrip pengguna" ke dalam /docker-entrypoint-initdb.d
penampung direktori. itu akan dieksekusi sekali, pada saat pod pertama dimulai.
apiVersion: extensions/v1beta1
kind: Pod
metadata:
name: mysql
spec:
containers:
- name: mysql
image: mysql
.....
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
.....
volumeMounts:
- name: mysql-initdb
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: mysql-initdb
configMap:
name: initdb
---
apiVersion: v1
kind: ConfigMap
metadata:
name: initdb
data:
initdb.sql: |-
CREATE USER 'first_user'@'%' IDENTIFIED BY '111' ;
CREATE USER 'second_user'@'%' IDENTIFIED BY '222' ;
Tes:
kubectl exec -it <PODNAME> -- mysql -uroot -p -e 'SELECT user, host FROM mysql.user;'
+-------------+------+
| user | host |
+-------------+------+
| first_user | % |
| second_user | % |
| root | % |
+-------------+------+
Lihat Menginisialisasi instance baru Gambar Hub Docker Mysql: