I'm using "hostpath" to access the .sql file into the volume.
When we enter into the mysql pod, there we can see the .sql file
("laravel/laravel.sql" the given path is define in the volume mount section)
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.
Please provide the proper solution of this problem
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
As you can read in Kubernetes documentation:
A hostPath volume mounts a file or directory from the host node’s filesystem into your Pod.
In addition to the required path property, user can optionally specify a type for a hostPath volume.
There are a few supported values for
type field. The one which you should use in your particular case is a
File which is defined as follows:
File A file must exist at the given path
In your deployment definition you should use full paths to the file like in the example below:
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
For using this type of volume you don't need a separate definition of
persistentVolumeClaim. It's totally enough if you just add it to your deployment definition. If for some reason you are interested in creating a
hostPath PersistentVolume it is nicely described here.
Last lines of your deployment definition may look like this:
volumeMounts: - name: mysql-volume mountPath: your_file.sql volumes: - name: mysql-volume hostPath: path: toyour_file.sql type: File