<p>I wanted to create some mysql users and databases while creating mysql deployment in kubernetes.
means when mysql deployment is being created its shouldalso create some users as well as database in the mysql.</p>
<p>Below is the deployment config i have created for mysql. let me know is it possible to add here some data which will create the user and database.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin
spec:
  ports:
  - port: 80
    protocol: TCP
    nodePort: 30081
  selector:
    app: mysql
  type: NodePort
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              configMapKeyRef:
                name: mysql-config
                key: mysql_root_password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      - image: phpmyadmin:5
        name: phpmyadmin
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: password
          - name: PMA_HOST
            value: mysql
        ports:
        - containerPort: 80
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/mnt/data&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
</code></pre>

<p>In the <a href="https://hub.docker.com/_/mysql" rel="nofollow noreferrer">mysql docker image</a> (under &quot;Initializing a fresh instance&quot;): you can use the <code>/docker-entrypoint-initdb.d</code> as a point to which to volume mount scripts and SQL files for database initialization.</p>
