<p>I have deployed a mysql database in kubernetes and exposed in via a service. When my application tries to connect to that database it keeps being refused. I also get the same when I try to access it locally. Kubernetes node is run in minikube.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  type: NodePort
  selector:
    app: mysql
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql_db
        imagePullPolicy: Never
        ports:
        - containerPort: 3306
        volumeMounts:
        - name:  mysql-persistent-storage
          mountPath:  "/var/lib/mysql"
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>

<p>And here's my yaml for persistent storage:</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec: 
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/Users/Work/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
</code></pre>

<p>After this I get this by running <code>minikube service list</code>:</p>

<pre><code>default              | mysql-service             | http://192.168.99.101:31613 
</code></pre>

<p>However I cannot access the database neither from my application nor my local machine.
What am I missing or did I misconfigure something?</p>

<p>EDIT:
I do not define any envs here since the image run by docker already a running mysql db and some scripts are run within the docker image too.</p>

davidb
<p>Ok, I figured it out. After looking through the logs I noticed the error <code>Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)</code>.</p>

<p>I had to add this to my docker image when building:
<code>RUN usermod -u 1000 mysql</code></p>

<p>After rebuilding the image everything started working. Thank you guys.</p>
