9

I'm extremely new to Kubernetes (besides it's not my field) but I got required to be able to execute this practice.

Question is that I need a Handbrake Converter in a containerized pod with a Persistent Volume mounted on a GKE cluster:

  • 3 nodes.
  • node version 1.8.1-gke.1
  • node image Ubuntu

Everything is fine until this point but now I'm not able to upload a folder to that PV from my local machine.

What I have tried is a ssh connection to the node and then a sudo docker exec -ti containerId bash but I just got rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"bash\\\": executable file not found in $PATH\"\n".

Thanks in advance.

4
  • We would need more details of your cluster. Are you using minikube, gke? Nov 6, 2017 at 16:35
  • It is a GKE cluster with 3 nodes. Node version: 1.8.1-gke.1. Image of the node: Ubuntu. I'm also sure that I'm accesing to the node the pod is allocated in. Nov 6, 2017 at 16:39
  • Try docker exec -ti containerId sh
    – svenwltr
    Nov 6, 2017 at 17:14
  • you need to use kubectl command to connect to container. kubectl exec -it <podname> -- /bin/bash
    – sfgroups
    Nov 6, 2017 at 17:50

1 Answer 1

16

To transfer local files to a kubernetes pod, use kubectl cp:

kubectl cp /root/my-local-file my-pod:/root/remote-filename

or

kubectl cp /root/my-local-file my-namepace/my-pod:/root/remote-filename -c my-container

The namespace can be omitted (and you'll get the default), and the container can be omitted (you'll get the first in the pod).

For SSH'ing you need to go through kubectl as well:

kubectl exec -it <podname> -- /bin/sh
5
  • 1
    # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir Jun 12, 2019 at 8:06
  • 5
    So this is the answer to upload files to a pod, but how can you upload directly to a persistent volume?
    – Sebi B
    Jun 24, 2021 at 7:07
  • @SebiB A persistent volume will need to be mounted and in use by a pod to be able to upload data to it.
    – vascop
    Jun 25, 2021 at 8:53
  • rather copying the files manually, Can we copy these files in docker image? COPY 'local_file' ./root and then in Volume Mounts can we do: volumeMounts: - mountPath: "/root/" Does this work? Aug 3, 2021 at 16:20
  • @ChaitanyaPatil that's probably a good separate question :) What I would do in that case is to define an initcontainer which cp's the files you need from the directory in your image into the path where you mount your persistent volume. Since the volume is persistent I'll leave it up to you to decide what happens if there's data already there from a previous container. Does it overwrite it? This use-case sounds a bit suspect :)
    – vascop
    Aug 3, 2021 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.