Editing
Tutorials:Persistent volumes on the Kubernetes cluster
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Reading/writing the contents of a persistent volume == You can access a PV which is bound to a PVC by mounting it into a container. For a demonstration, we use the simple container image "ubuntu:18.04", which runs a minimalistic Ubuntu, and keep it in a very long wait after container startup. <syntaxhighlight lang="yaml"> # Test pod to mount a PV bound to a PVC into a container # Before starting this pod, apply the PVC with kubectl apply -f pvc.yaml apiVersion: v1 kind: Pod metadata: name: your-username-pvc-access-pod spec: containers: - name: pvc-access-container # we use a small ubuntu base to access the PVC image: ubuntu:18.04 # make sure that we have some time until the container quits by itself command: ['sleep', '6h'] # list of mount paths within the container which will be # bound to persistent volumes. volumeMounts: - mountPath: "/mnt/pvc-mnist" # name of the volume for this path (from the below list) name: pvc-mnist volumes: # User-defined name of the persistent volume within this configuration. # This can be different from the name of the PVC. - name: pvc-mnist persistentVolumeClaim: # name of the PVC this volume binds to claimName: your-username-tf-mnist-pvc </syntaxhighlight> After the PVC is applied, spin up the test pod with <syntaxhighlight lang="yaml"> > kubectl apply -f pvc-access-pod.yaml </syntaxhighlight> You now have several options to get data to and from the container. === 1. Copying data from within the container === You can get a root shell inside the container as usual (insert the correct pod name you used below): <syntaxhighlight lang="yaml"> > kubectl exec -it pvc-access-pod /bin/bash </syntaxhighlight> Your pod has internet access. Thus, an option to get data to/from the pod, in particular into the persistent volume, is to use scp, which first needs to be installed inside the pod: <syntaxhighlight lang="yaml"> # apt-get update && apt install openssh-client rsync # cd /my-pvc-mount-path # scp your.username@external-server:/path/to/data/. ./ </syntaxhighlight> An even better variant would be "rsync -av" instead of scp, as this only copies files which are different or do not exist in the destination. By reversing source and destination, you can also copy data out of the container this way. === 2. Copying data from the outside === From the outside world, you can directly copy data to and from the container using kubectl cp, which has a very similar syntax as scp: <syntaxhighlight lang="yaml"> # to get data into the container, substitute name with correct id obtained from kubectl get pods > kubectl cp /path/to/data/. pvc-access-pod:/my-pvc-mount/path/data # to get data from the container > kubectl cp pvc-access-pod:/my-pvc-mount/path/. /path/to/output/ </syntaxhighlight> Read up on Kubernetes "kubectl cp" documentation to check how it handles directories, it's a bit unusual and slightly different from scp. Note: kubectl cp internally uses tar and some compression to speed up network transfer. However, this means that your access pod needs a certain amount of memory, in particular when transferring large files. If you run into "error 137" (out of memory), increase memory limits of the access pod or use scp from within the pod. [[Category:Tutorials]]
Summary:
Please note that all contributions to Collective Computational Unit may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
CCU:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Collective Computational Unit
Main page
Projects
Tutorials
GPU Cluster
Core Facilitys
Mediawiki
Recent changes
Random page
Help
Tools
What links here
Related changes
Page information