<p>I'm using "hostpath" to access the .sql file into the volume. </p>

<p>When we enter into the mysql pod, there we can see the .sql file </p>

<p>("laravel/laravel.sql" the given path is define in the volume mount section)</p>

<p>But it's become directory not file and i'm unable to add .sql file into the database.
Currently the size of .sql file is 50Mi so unable to use configmap. </p>

<p>Please provide the proper solution of this problem </p>

<p><a href="https://i.stack.imgur.com/jt0S7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jt0S7.png" alt="mysql pod image"></a></p>

<p>mysql.yaml</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /home/paradise/lara_k8s/docker_qa-laravel
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
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"
          value: "root"
        - name: "MYSQL_USERNAME"
          value: "root"
        - name: "MYSQL_PASSWORD"
          value: "root"
        - name: "MYSQL_DATABASE"
          value: "homestead"
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /laravel
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>

Saya Kasta
<p>As you can read in <strong>Kubernetes</strong> <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">documentation</a>:</p>

<blockquote>
  <p>A hostPath volume mounts a file or directory from the host node’s
  filesystem into your Pod.</p>
</blockquote>

<p>and further:</p>

<blockquote>
  <p>In addition to the required path property, user can optionally specify a type for a hostPath volume.</p>
</blockquote>

<p>There are a few supported values for <code>type</code> field. The one which you should use in your particular case is a <code>File</code> which is defined as follows:</p>

<blockquote>
  <p>File  A file must exist at the given path</p>
</blockquote>

<p>In your deployment definition you should use full paths to the file like in the example below:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test/file.sql
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /data/file.sql
      type: File
</code></pre>

<p>For using this type of volume you don't need a separate definition of <code>persistentVolume</code> and <code>persistentVolumeClaim</code>. It's totally enough if you just add it to your deployment definition.
If for some reason you are interested in creating a <code>hostPath PersistentVolume</code> it is nicely described <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume" rel="nofollow noreferrer">here</a>.</p>

<p>EDIT:</p>

<p>Last lines of your deployment definition may look like this:</p>

<pre><code>    volumeMounts:
    - name: mysql-volume
      mountPath: /laravel/your_file.sql
  volumes:
  - name: mysql-volume
    hostPath:
      path: /path/to/file/your_file.sql
      type: File
</code></pre>
