<p>I am trying to create a Django + MySQL app using Google Container Engine and Kubernetes. Following the docs from official MySQL docker image and Kubernetes docs for creating MySQL container I have created the following replication controller</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    name: mysql
  name: mysql
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mysql
    spec:
      containers:
      - image: mysql:5.6.33
        name: mysql
        env:
          #Root password is compulsory
        - name: "MYSQL_ROOT_PASSWORD"
          value: "root_password"
        - name: "MYSQL_DATABASE"
          value: "custom_db"
        - name: "MYSQL_USER"
          value: "custom_user"
        - name: "MYSQL_PASSWORD"
          value: "custom_password"
        ports:
        - name: mysql
          containerPort: 3306
        volumeMounts:
          # This name must match the volumes.name below.
          - name: mysql-persistent-storage
            mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          gcePersistentDisk:
            # This disk must already exist.
            pdName: mysql-disk
            fsType: ext4
</code></pre>

<p>According to the docs, passing the environment variables MYSQL_DATABASE. MYSQL_USER, MYSQL_PASSWORD, a new user will be created with that password and assigned rights to the newly created database. But this does not happen. When I SSH into that container, the ROOT password is set. But neither the user, nor the database is created. </p>

<p>I have tested this by running locally and passing the same environment variables like this</p>

<pre><code>docker run -d --name some-mysql \
    -e MYSQL_USER="custom_user" \
    -e MYSQL_DATABASE="custom_db" \
    -e MYSQL_ROOT_PASSWORD="root_password" \
    -e MYSQL_PASSWORD="custom_password" \
    mysql
</code></pre>

<p>When I SSH into that container, the database and users are created and everything works fine.</p>

<p>I am not sure what I am doing wrong here. Could anyone please point out my mistake. I have been at this the whole day.</p>

<p>EDIT: 20-sept-2016</p>

<p>As Requested
@Julien Du Bois 
The disk is created. it appears in the cloud console and when I run the describe command I get the following output</p>

<pre><code>Command : gcloud compute disks describe mysql-disk

Result: 
creationTimestamp: '2016-09-16T01:06:23.380-07:00'
id: '4673615691045542160'
kind: compute#disk
lastAttachTimestamp: '2016-09-19T06:11:23.297-07:00'
lastDetachTimestamp: '2016-09-19T05:48:14.320-07:00'
name: mysql-disk
selfLink: https://www.googleapis.com/compute/v1/projects/&lt;details-withheld-by-me&gt;/disks/mysql-disk
sizeGb: '20'
status: READY
type: https://www.googleapis.com/compute/v1/projects/&lt;details-withheld-by-me&gt;/diskTypes/pd-standard
users:
- https://www.googleapis.com/compute/v1/projects/&lt;details-withheld-by-me&gt;/instances/gke-cluster-1-default-pool-e0f09576-zvh5
zone: https://www.googleapis.com/compute/v1/projects/&lt;details-withheld-by-me&gt;
</code></pre>

<p>I referred to lot of tutorials and google cloud examples. To run the mysql docker container locally my main reference was the official image page on docker hub
<a href="https://hub.docker.com/_/mysql/" rel="nofollow">https://hub.docker.com/_/mysql/</a></p>

<p>This works for me and locally the container created has a new database and user with right privileges.</p>

<p>For kubernetes, my main reference was the following</p>

<p><a href="https://cloud.google.com/container-engine/docs/tutorials/persistent-disk/" rel="nofollow">https://cloud.google.com/container-engine/docs/tutorials/persistent-disk/</a></p>

<p>I am just trying to connect to it using Django container. </p>

<p>I was facing the same issue when I was using volumes and mounting them to mysql pods.</p>

<p>As mentioned in the documentation of <a href="https://docs.docker.com/samples/library/mysql/" rel="nofollow noreferrer">mysql's docker image</a>:</p>

<blockquote>
  <p>When you start the mysql image, you can adjust the configuration of the MySQL instance by passing one or more environment variables on the docker run command line. <strong>Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.</strong></p>
</blockquote>

<p>So after spinning wheels I managed to solve the problem by changing the hostPath of the volume that I was creating from "/data/mysql-pv-volume" to "/var/lib/mysql"</p>

<p>Here is a code snippet that might help create the volumes</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  persistentVolumeReclaimPolicy: Delete /* For development Purposes only */
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/var/lib/mysql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
</code></pre>

<p>Hope that helped.</p>
