Although containers are ephemeral, there are often cases where data must be persisted so as to not lose any files. Ketch can be used to seamlessly deploy an application that binds to an existing persistent volume to not lose any of this essential data. This is done by attaching a Persistent Volume Claim (PVC) to the Ketch App at a specified directory path.
To learn more about PVC's: Kubernetes Documentation
A bounded PVC must exist prior to deploying an application. In the case that a PVC has been created, you must ensure that a matching volume exists. Ketch will validate the parameters being passed in as well as check that the PVC exists.
Here is a sample manifest:
apiVersion: v1 kind: PersistentVolume metadata: name: pv-volume-1 labels: type: local spec: storageClassName: manual capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data" --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-1 spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 3Gi
The example below illustrates all of the parameters pertaining to mounting a volume as well as Pod Security Policies that can be set.
The volume flag must be set if any of the volume related flags are being used.
ketch app deploy <app-name> -i <image> -k <framework-name> --volume <pvc-name> --volume-mount-path <volume-mount-path> --fs-group <group-id> --volume-mount-options <volume-mount-options> --run-as-user <user-id>
|--volume||Name of the volume to bind to the application.||pvc-1|
|--volume-mount-path||Path to mount a volume.||/var/lib/mysql|
|--fs-group||The fsGroup for pod's security context; root if not set.||1|
|--volume-mount-options||Options for volume mount. (default )||readOnly=true|
|--run-as-user||The user to use for running pod's processes; root if not set||0|
After the application is deployed, you can verify that the volume exists in the container. In the example below, the pod name is fetched and the
ls command is then executed to check if the volume exists.
kubectl describe pods | grep Name kubectl exec -it <pod-name> -- /bin/bash -c "ls </volume/path>"
Updated 7 months ago