<p>I am facing issues when mounting a path.My objective is to make the data persistent even when the pod restarts.But its creating a new directory which doesnt have any of my config files.</p>

<pre><code>FROM centos:7
ENV DIR /binaries
ENV PASS admin
WORKDIR ${DIR}
COPY libstdc++-4.8.5-39.el7.x86_64.rpm ${DIR} 
COPY numactl-libs-2.0.12-3.el7.x86_64.rpm ${DIR}
COPY mysqlmonitor-8.0.18.1217-linux-x86_64-installer.bin ${DIR}
RUN yum install -y libaio &amp;&amp; yum -y install gcc &amp;&amp; yum -y install gcc-c++ &amp;&amp; yum -y install compat-libstdc++-33 &amp;&amp; yum -y install libstdc++-devel &amp;&amp; yum -y install elfutils-libelf-devel &amp;&amp; yum -y install glibc-devel &amp;&amp; yum -y install libaio-devel &amp;&amp; yum -y install sysstat
RUN yum install -y gcc &amp;&amp; yum install -y make &amp;&amp; yum install -y apr-devel &amp;&amp; yum install -y openssl-devel &amp;&amp; yum install -y java
RUN rpm -ivh numactl-libs-2.0.12-3.el7.x86_64.rpm
RUN useradd sql
RUN chown sql ${DIR}
RUN chmod 777 ${DIR}
RUN chmod 755 /home/sql
USER sql
WORKDIR ${DIR}
RUN ./mysqlmonitor-8.0.18.1217-linux-x86_64-installer.bin --installdir /home/sql/mysql/enterprise/monitor --mode unattended --tomcatport 18080 --tomcatsslport 18443 --adminpassword ### --dbport 13306
RUN rm -rf /binaries/*
VOLUME /home/sql/mysql/enterprise/monitor/mysql/data
ENTRYPOINT ["/bin/bash", "-c", "/home/sql/mysql/enterprise/monitor/mysqlmonitorctl.sh start &amp;&amp; tail -f /home/sql/mysql/enterprise/monitor/apache-tomcat/logs/mysql-monitor.log"]
</code></pre>

<pre><code>Deployment yaml file
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mypod
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mem     
  template:
    metadata:
      labels:
        app: mem
    spec:
      containers:
      - name: mem
        image: 22071997/mem
        command: 
        volumeMounts:
        - mountPath: /home/sql/mysql/enterprise/mysql/data
          name: volume
      volumes:
      - name: volume
        persistentVolumeClaim:
          claimName: mem-
</code></pre>

<pre><code>Output:
[sql@mypod-67cb4f85b8-9km26 data]$ pwd
/home/sql/mysql/enterprise/mysql/data
[sql@mypod-67cb4f85b8-9km26 data]$ ls
[sql@mypod-67cb4f85b8-9km26 data]$
</code></pre>

<p>Expected output: I need all my data to be present.</p>

Sowmiya 
<p>Please check the following:</p>

<ul>
<li>You use Dockerfile VOLUME for the purpose of persisting data from the container volume /home/sql/mysql/enterprise/monitor/mysql/data in the host volume  <a href="https://stackoverflow.com/questions/41935435/understanding-volume-instruction-in-dockerfile">/var/lib/docker/volumes/...</a> (ie. for every node this data will be unique -- it's way there exists the PersistentVolume abstraction on Kubernetes)</li>
</ul>

<p>If not:</p>

<ul>
<li>There exists a PersistentVolume abstraction in the cluster (kubectl get pv). It has a valid PersistentVolume.spec.type (e.g. nfs, hostPath)</li>
<li>There exists a PersistentVolumeClaim abstraction (kubectl get pvc) in the cluster</li>
<li>There exists a Deployment abstraction (kubectl get deploy) in the cluster</li>
<li>PersistentVolumeClaim.spec.volumeName matches PersistentVolume.metadata.name (or PersistentVolume.spec.claimRef.name matches PersistentVolumeClaim.metadata.name)</li>
<li>Deployment.spec.template.spec.volumes[].persistentVolumeClaim.claimName matches PersistentVolumeClaim.metadata.name</li>
<li>Deployment.spec.template.spec.containers[].volumeMounts[].name matches Deployment.spec.template.spec.volumes[].name</li>
</ul>

<p>Debugging:</p>

<ul>
<li>Locate the PersistentVolume plugin mount path. Let's take my Minikube cluster as an example. I'm using:</li>
</ul>

<pre><code>$ kubectl get pv -o=jsonpath='{.items[0].spec.hostPath.path}'
/tmp/hostpath-provisioner/pvc-5e497ae8-943e-4651-86b9-4355c48d443dsv
</code></pre>

<ul>
<li>Create a sample file:</li>
</ul>

<pre><code>$ touch /tmp/hostpath-provisioner/pvc-5e497ae8-943e-4651-86b9-4355c48d443d/1
$ ls /tmp/hostpath-provisioner/pvc-5e497ae8-943e-4651-86b9-4355c48d443d
1
</code></pre>

<ul>
<li>Create deployment following the above mentioned checks:</li>
</ul>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: test
  name: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test
    spec:
      containers:
      - image: busybox
        command:
          - sleep
          - "10000"
        name: busybox
        resources: {}
        volumeMounts:
          - mountPath: /tmp/test_dir
            name: my-volume
      volumes:
      - name: my-volume
        persistentVolumeClaim:
            claimName: myclaim
</code></pre>

<ul>
<li>Test whether the file exists in the designated directory:</li>
</ul>

<pre><code>$ kubectl exec test-6f857854db-57fsz -- ls /tmp/test_dir
1
</code></pre>
