Sergio Arrighi
Sergio Arrighi

Reputation: 530

kubectl cp bitnami apache helm chart: cannot copy to exact location of pod filesystem

I'm trying to deploy a react app on my local machine with docker-desktop and its kubernetes cluster with bitnami apache helm chart.
I'm following this this tutorial.
The tutorial makes you publish the image on a public repo (step 2) and I don't want to do that. It is indeed possible to pass the app files through a persistent volume claim.
This is described in the following tutorial.

Step 2 of this second tutorial lets you create a pod pointing to a PVC and then asks you to copy the app files there by using command

kubectl cp /myapp/* apache-data-pod:/data/

My issues:

  1. I cannot use the * wildcard or else I get an error. To avoid this I just run

kubectl cp . apache-data-pod:/data/

  1. This instruction copies the files in the pod but it creates another data folder in the already existing data folder in the pod filesystem
    After this command my pod filesystem looks like this enter image description here I tried executing

kubectl cp . apache-data-pod:/

But this copies the file in the root of the pod filesystem at the same location where first data folder is.

I need to copy the data directly in <my_pod>:/data/. How can I achieve such behaviour?

Regards

Upvotes: 0

Views: 413

Answers (1)

Veera Nagireddy
Veera Nagireddy

Reputation: 1894

**Use the full path in the command as mentioned below to copy local files to POD : *

kubectl cp apache-pod:/var/www/html/index.html /tmp

*If there are multiple containers on the POD, Use the below syntax to copy a file from local to pod:

kubectl cp /<path-to-your-file>/<file-name> <pod-name>:<fully-qualified-file-name> -c <container-name>

Points to remember :

  1. While referring to the file path on the POD. It is always relative to the WORKDIR you have defined on your image.
  2. Unlike Linux, the base directory does not always start from the / workdir is the base directory
  3. When you have multiple containers on the POD you need to specify the container to use with the copy operation using -c parameter

Quick Example of kubectl cp : Here is the command to copy the index.html file from the POD’s /var/www/html to the local /tmp directory.

No need to mention the full path, when the doc root is the workdir or the default directory of the image.

kubectl cp apache-pod:index.html /tmp

To make it less confusing, you can always write the full path like this

kubectl cp apache-pod:/var/www/html/index.html /tmp

*Also refer to this stack question for more information.

Upvotes: 1

Related Questions