Pixzium Media
Pixzium Media

Reputation: 139

Unable to install curl command in kubernetes pod

I am using the below command to install curl in one of the pods:

$ apt-get install curl

But , I am getting below error:

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

When I am trying to remove the file /var/lib/dpkg/lock-frontend

$ rm /var/lib/dpkg/lock-frontend
rm: remove write-protected regular empty file '/var/lib/dpkg/lock-frontend'? y
rm: cannot remove '/var/lib/dpkg/lock-frontend': Permission denied

I can't use sudo command also :

$ sudo rm /var/lib/dpkg/lock-frontend
bash: sudo: command not found

Please help, as I am new to Kubernetes and Pods.

Upvotes: 0

Views: 6853

Answers (2)

Adrian Escutia
Adrian Escutia

Reputation: 1069

If you are trying to troubleshoot from the container, you can try to leverage bash's built-in TCP/UDP socket support, for example:

HOSTNAME=google.com; PORT=80
echo >/dev/tcp/$HOSTNAME/$PORT && echo "Open" || echo "Closed"

If your pod/container has a programming language installed, Python, Ruby, or Node you can use a single bash line to test as well. Take a look at the different options I prepared here https://go.rebelion.la/uSTroubleshooting

Upvotes: 0

whites11
whites11

Reputation: 13260

First of all this is a anti-pattern. Containers are meant to be stateless and not change after they are deployed.

The reason why you can't run apt-get is because you are running your container with an unprivileged user as you can tell by the "$" sign in your command prompt. Also sudo is not installed and thus not usable.

If you really want to have curl in your container you have a couple of options:

  • Extend your docker image, and install curl at build time rather than at run time
  • Run your container as root and install curl from an interactive session as you tried to do (discouraged).

Example of the first approach, the one I suggest you to use, involves a Dockerfile like the following:

FROM the-image-name-you-are-currently-using

RUN apt-get update; apt-get install -y curl

You then need to build this new image with (from the same directory where your Dockerfile is):

docker build -t your-new-image-name:version .

After you pushed the image to a registry with docker push you can update your Pod to use your-new-image-name:version as image.

Upvotes: 2

Related Questions