<p>I have a nodejs app running as a Service that requires access to a mysql database running as another service (same namespace).</p>
<p>I also have a mysql file that I will be importing to the database.</p>
<p>here is my workflow :</p>
<ol>
<li><p>Set up a Secret that contain the root password alongside new database credentials (db_name, db_user, db_password).</p>
</li>
<li><p>Set up a ConfigMap with SQL script to create the db structure.</p>
</li>
<li><p>Finally, deploy mysql with pv/pvc, here is the yaml file content :</p>
</li>
</ol>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  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: 1Gi
---      
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
---
apiVersion: apps/v1 
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:
            secretKeyRef:
              name: mysql-secrets
              key: DB_ROOT
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              name: mysql-secrets
              key: DB_NAME
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: mysql-secrets
              key: DB_USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secrets
              key: DB_PASS
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
        - name: mysql-initdb
          mountPath: /docker-entrypoint-initdb.d
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim        
      - name: mysql-initdb
        configMap:
          name: mysql-initdb-config

</code></pre>
<p>Because my nodejs app doesn't access the database, I wanted to verify if the new db has been created and the sql file imported, running <code>kubectl exec</code>  followed by <code>mysql -u root -p</code> is giving me this error :</p>
<pre><code>ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
</code></pre>
<p>Within the pod, running <code>echo $MYSQL_ROOT_PASSWORD</code> or any other env variables returns the correct value.</p>
<p>What am I doing wrong ?</p>

jaquemus
<p>Solved the issue by editing the line : <code>mountPath: /var/lib/mysql</code></p>
<p>I changed it to <code>/mnt/data</code> and the deployment works like a charm.</p>
