<p>Sup. I created my service, deployment and persistent volume claim so my mysql sholud work inside minikube, but it doesn't. I can't figure out why docker container outside minikube works fine, but when i try to use it inside minikube cluster my database purges somehow. Here's my Dockerfile</p>
<pre><code>FROM alpine:latest
RUN apk update &amp;&amp; apk upgrade -a -U
RUN apk add mysql mysql-client openrc supervisor
RUN chown -R mysql:mysql /var/lib/mysql/
COPY ./my.cnf /etc/
COPY ./secure_config.sh /root
RUN rc default
RUN /etc/init.d/mariadb setup
RUN /etc/init.d/mariadb start
RUN chmod 755 /root/secure_config.sh
RUN /root/secure_config.sh
RUN sed -i &quot;s|.*bind-address\s*=.*|bind-address=0.0.0.0|g&quot; /etc/my.cnf
RUN sed -i &quot;s|.*bind-address\s*=.*|bind-address=0.0.0.0|g&quot; /etc/my.cnf.d/mariadb-server.cnf
RUN sed -i &quot;s|.*skip-networking.*|skip-networking|g&quot; /etc/my.cnf
RUN sed -i &quot;s|.*skip-networking.*|skip-networking|g&quot; /etc/my.cnf.d/mariadb-server.cnf
COPY ./wpdb.sh .
COPY ./sql_launch.sh .
RUN chmod 755 /wpdb.sh
RUN chmod 755 /sql_launch.sh
COPY ./supervisord.conf /etc/
EXPOSE 3306
CMD /sql_launch.sh
</code></pre>
<p>wpdb.sh</p>
<pre><code>mysql -e &quot;CREATE DATABASE wordpress;&quot;
mysql -e &quot;CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin';&quot;
mysql -e &quot;CREATE USER 'lchantel'@'localhost' IDENTIFIED BY 'lchantel';&quot;
mysql -e &quot;CREATE USER 'pstein'@'localhost' IDENTIFIED BY 'pstein'&quot;
mysql -e &quot;CREATE USER 'admins_mom'@'localhost' IDENTIFIED BY 'admins_mom'&quot;
mysql -e &quot;DELETE FROM mysql.user WHERE user = '';&quot;
mysql -e &quot;SET PASSWORD FOR 'admins_mom'@'localhost' = PASSWORD('123456');&quot;
mysql -e &quot;SET PASSWORD FOR 'admin'@'localhost' = PASSWORD('123456');&quot;
mysql -e &quot;SET PASSWORD FOR 'pstein'@'localhost' = PASSWORD('123456');&quot;
mysql -e &quot;SET PASSWORD FOR 'lchantel'@'localhost' = PASSWORD('123456');&quot;
mysql -e &quot;GRANT ALL PRIVILEGES ON wordpress.* TO 'admin'@'localhost' IDENTIFIED BY 'admin';&quot;
mysql -e &quot;FLUSH PRIVILEGES;&quot;
</code></pre>
<p>sql_launch.sh</p>
<pre><code>#!bin/sh

rc default
chmod 777 /wpdb.sh &amp;&amp; /wpdb.sh
rc-service mariadb stop
/usr/bin/supervisord -c /etc/supervisord.conf
</code></pre>
<p>This is my mysql output within the container</p>
<pre><code>MariaDB [(none)]&gt; SELECT user FROM mysql.user
    -&gt; ;
+-------------+
| User        |
+-------------+
| admin       |
| admins_mom  |
| lchantel    |
| mariadb.sys |
| mysql       |
| pstein      |
| root        |
+-------------+
7 rows in set (0.006 sec)
MariaDB [(none)]&gt;
</code></pre>
<p>and this is my outputs inside minikube pod</p>
<pre><code># rc-status
Runlevel: default
 mariadb                                                                                                                                                                      [  stopped  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
Dynamic Runlevel: manual
/ # rc-service mariadb start
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/blkio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpu/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpu,cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuset/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/devices/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/freezer/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/hugetlb/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/memory/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/net_cls/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/net_cls,net_prio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/net_prio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/perf_event/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/pids/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/systemd/tasks: Read-only file system
 * Datadir '/var/lib/mysql/' is empty or invalid.
 * Run '/etc/init.d/mariadb setup' to create new database.
 * ERROR: mariadb failed to start
</code></pre>
<p>And so i guess problem is in yaml file in mountPath section of deployment. There're yaml files</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-mysql
spec:
  capacity:
    storage: 500Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/home/lchantel/pv_proj/&quot;

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-mysql
  labels:
    app: mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
</code></pre>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: wildboar-mysql-service
  labels:
    app: mysql
spec:
  type: ClusterIP
  selector:
    app: mysql
  ports:
    - name: mysql
      port: 3306
      targetPort: 3306
      protocol: TCP
  clusterIP: None

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wildboar-mysql-deploy
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: wildboar-mysql-pod
          image: wildboar.mysql:latest
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysqldb-storage
              mountPath: /var/lib/mysql/
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: root
          imagePullPolicy: Never
      volumes:
        - name: mysqldb-storage
          persistentVolumeClaim:
            claimName: pv-claim-mysql
</code></pre>
<p>Google doesn't help and simply don't know what should i do and where shoud i start from.</p>

WildBoar
<p>Well, i solved my problem next way</p>
<ol>
<li>I totally remade my mysql Dockerfile. The way alpine wiki suggest to configure mariadb is complicate and doesn't work. <code>VOLUME /var/lib/mysql/</code> command was pretty usefull for persisting data in thata directory.</li>
<li>I decided to turn .sh to mysql script. And, as far as I manage to use my database for Wordpress there is no reason to create several users in mysql database. It's enough to create one admin. Here is my Dockerfile</li>
</ol>
<pre><code>FROM alpine:latest
RUN apk update &amp;&amp; apk upgrade -a -U
RUN apk add mysql mysql-client openrc supervisor
COPY ./mariadb-server.cnf /etc/my.cnf
RUN chmod 755 /etc/my.cnf 
RUN mkdir /sql_data
COPY ./wpdb.sql /sql_data
COPY ./launch.sh /
RUN chmod 755 ./launch.sh
RUN chown -R mysql:mysql /sql_data
VOLUME /var/lib/mysql/
RUN mkdir -p /run/mysqld/
EXPOSE 3306
CMD /launch.sh 
</code></pre>
<p>and sql script</p>
<pre><code>CREATE DATABASE wordpress;
DELETE FROM mysql.user WHERE user = '';
GRANT ALL PRIVILEGES ON wordpress.* TO 'admin'@'%' IDENTIFIED BY 'admin';
SET PASSWORD FOR 'admin'@'%' = PASSWORD('admin');
FLUSH PRIVILEGES;
</code></pre>
<ol start="3">
<li>Superviror service is usefull when you run 2 and more services (supervisord excluded) in the same time. So it's enough to use script with myslq setup and launching it as daemon:</li>
</ol>
<pre><code>#!/bin/sh

mysql_install_db --skip-test-db --user=mysql --datadir=/var/lib/mysql
mysqld --user=mysql --datadir=/var/lib/mysql --init-file=/sql_data/wpdb.sql
</code></pre>
<ol start="4">
<li>There's some little changes in yaml file. We created admin is mysql script, so there is no need to create it in yaml file.</li>
</ol>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  labels:
    app: mysql
spec:
  type: ClusterIP
  selector:
    app: mysql
  ports:
    - name: mysql
      port: 3306
      targetPort: 3306
      protocol: TCP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      restartPolicy: Always
      containers:
        - name: mysql
          image: mysql:latest
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysqldb-storage
              mountPath: &quot;/var/lib/mysql/&quot;
          imagePullPolicy: Never
      volumes:
        - name: mysqldb-storage
          persistentVolumeClaim:
            claimName: pv-claim-mysql
</code></pre>
<ol start="5">
<li>There are some changes in my.cnf configuration file.</li>
</ol>
<pre><code>#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
user=root
port=3306
datadir=/var/lib/mysql
tmpdir=/tmp
skip-networking=false
socket=/run/mysqld/mysqld.sock
wait_timeout = 600
max_allowed_packet = 64M
# Galera-related settings
#[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# Disabling symbolic links is recommended to prevent assorted security risks
symbolic-links=0

# this is only for embedded server
[embedded]

</code></pre>
