Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`kubectl cp` to a pod is failing because of Permission Denied

When I try to copy a small file to a Kubernetes pod, it fails with the following error:

:~ $kubectl cp /tmp/a default/resolver-proxy-69dc786fcf-5rplg:/usr/local/bin/ --no-preserve=true
    tar: a: Cannot open: Permission denied
    tar: Exiting with failure status due to previous errors
    command terminated with exit code 2

Could someone please help me how to fix this? I am running Kubernetes on minikube.

I also see another Postgres Pod in a Error state because of similar error:

:~ $kubectl logs postgres-7676967946-7lp9g postgres
tar: /var/lib/postgresql/data: Cannot open: Permission denied
tar: Error is not recoverable: exiting now
like image 423
UnderWood Avatar asked Aug 31 '19 01:08

UnderWood


People also ask

What does Kubectl CP do?

Kubectl cp command is most widely used to copy files between pods and local file system. It is more like SCP in Linux world to copy files between local to remote machines using ssh protocol.

Does Kubectl CP overwrite?

it will only override the destination different_file.


1 Answers

For kubectl cp try copying first to /tmp folder and then mv the file to the path required by shifting to root user

kubectl cp /tmp/a default/resolver-proxy-69dc786fcf-5rplg:/tmp/

then exec into the pod and change to root and copy to the path required.

For the second issue exec into the pod and fix the permissions by running the below command. Postgres need to be able to read and write to the Postgres path.

chown -R postgres:postgres /var/lib/postgresql/

like image 191
Tummala Dhanvi Avatar answered Oct 06 '22 21:10

Tummala Dhanvi