Skip to content

EKS Pods content copying issue

0

I'm trying to copy a log file from a Kubernetes pod to my local machine using the following kubectl command in PowerShell:

powershell Copy code kubectl cp -n uat jeet-342asdc4:C:\app\20240821-remoteapi.log C:\logs\error.txt However, I keep getting the following error: tar: Couldn't open C:/app/20240821-remoteapi.log: Permission denied tar: Error exit delayed from previous errorr I don't want to copy the logs inside the pod from one destination to another.

How can I resolve this permission issue, and what are the recommended steps to successfully copy the file to my local machine?

Any insights or suggestions from the AWS community would be greatly appreciated!

2 Answers
2
Accepted Answer

Use an Intermediate Directory Inside the Pod

Sometimes, copying directly from a certain path may cause issues. Try copying the log file to a different directory within the pod first, and then perform the kubectl cp:

kubectl exec -n uat jeet-342asdc4 -- cmd /c "copy C:\app\20240821-remoteapi.log C:\temp\20240821-remoteapi.log"

Then, copy the file from the new location:

kubectl cp -n uat jeet-342asdc4:C:\temp\20240821-remoteapi.log C:\logs\error.log

If need it for dev environment, it can be done with pod security constraints.

spec:
  template: 
    spec:
      containers:
        ...
        securityContext:
          runAsUser: 0

As a result kubectl is connected to pod as root

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years ago
1

Hello,

indicates that the Kubernetes pod doesn't have the necessary permissions to access the specified file within the container.

1.Check file permissions within the container:

  • Use kubectl exec jeet-342asdc4 -c app sh to enter the container's shell.
  • Run ls -l C:\app\20240821-remoteapi.log to see the file's permissions.
  • If the file doesn't have read permissions for the user running the kubectl cp command, use chmod 444 C:\app\20240821-remoteapi.log to make it readable by everyone.

2.Run the kubectl cp command with appropriate permissions:

  • If you're using a non-root user, you might need to use sudo kubectl cp ....
  • Ensure you have the necessary permissions on your local machine to write to the C:\logs directory.

Example:

sudo kubectl cp -n uat jeet-342asdc4:C:\app\20240821-remoteapi.log C:\logs\error.txt

If this doesn't work, try:

  • Checking volume permissions: If the file is in a volume, verify its permissions on the host machine.
  • Reviewing the pod's security context: Ensure the pod has the necessary permissions to access the file.
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
  • Hi NARRAVULA, I was testing so I found the way to get the specific stream between to time stamps using Get-Content command in powershell and that's working fine for me

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.