I am running application on k8s.
My docker file is like :
FROM python:3.5 AS python-build
ADD . /test
WORKDIR /test
in test directory, i am doing everything my files inside this test folder.
when i go inside pod and check file structure it's like /var /usr /test /bin
so i want to add whole folder test in pvc
in test file structure is like /app /data /history
so can i save add folder attach to pvc using mountpath?
is it possible two mountpath but one pvc ?
As I understand, you want to include your test directory as a mount path in your PVC. To answer that question, yes you can do it by providing it in the hostpath not the mount path. As explained in the documentation :-
A hostPath volume mounts a file or directory from the host node’s filesystem into your Pod. This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.
and a mount path is -
The location in pod where the volume should be mounted.
so, if from your host system you want to mount the \test folder you need to provide it in the pv like below
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/test"
and you can use this PV to claim a volume using pvc and use the mountPath to mount that volume into your pod.
To answer your second question, yes you can have multiple mount paths for a single PVC. An example of this which works is :-
"containers": [
{
...,
"volumeMounts": [
{
"mountPath": "/mnt/1",
"name": "v1",
"subPath": "data/1"
},
{
"mountPath": "/mnt/2",
"name": "v1",
"subPath": "data/2"
}
]
}
],
...,
"volumes": [
{
"name": "v1",
"persistentVolumeClaim": {
"claimName": "testvolume"
}
}
]
}
}
For mount points stuff, you don't have deal with PVC
, but PV
s and volumeMounts
in deployment yaml. From Docs
PVC
A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a pod.
PV
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator.
And yes, you can do that. Just Create PV(or Dont have to, depends on cluster configuration. PVs will create from PVCs) and specify volumeMounts
in your deployment
Check out my yaml files in my repo
PV Example with storage as NFS
- https://github.com/veerendra2/my-k8s-applications/blob/master/pv/pv.yaml
Deployement Example with volumeMounts
- https://github.com/veerendra2/my-k8s-applications/blob/master/spinnaker/minio.yaml#L55
PVC Example incase if you need - https://github.com/veerendra2/my-k8s-applications/blob/master/pv/pvc.yaml