ERJAN
ERJAN

Reputation: 24500

how to make curl available in my container in k8s pod?

I'm using busybox image in my pod. I'm trying to curl another pod, but "curl is not found". How to fix it?

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: front
  name: front
spec:
  containers:
  - image: busybox
    name: front
    command:
    - /bin/sh
    - -c
    - sleep 1d

this cmd:

k exec -it front -- sh
curl service-anotherpod:80 -> 'curl not found'

Upvotes: 1

Views: 5345

Answers (3)

majorgear
majorgear

Reputation: 337

You could make your own image and deploy it to a pod. Here is an example Dockerfile

FROM alpine:latest

RUN apk update && \
    apk upgrade && \
    apk add --no-cache \
        bind-tools \
        curl \
        iproute2 \
        wget \
        && \
        : 
ENTRYPOINT [ "/bin/sh", "-c", "--" , "while true; do sleep 30; done;" ]

Which you can then build like this

docker image build -t networkutils:latest  . 

Run like this

docker container run -rm -d --name networkutils networkutils

And access it's shell to run curl, wget, or whichever commands you have installed like this

docker container exec -it networkutils sh

To run and access it in k3s you can do make a deployment file like this

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: networkutils
  namespace: default
  labels:
    app: networkutils
spec:
  replicas: 1
  selector:
    matchLabels:
      app: networkutils
  template:
    metadata:
      labels:
        app: networkutils
    spec:
      containers:
      - name: networkutils-container
        image: networkutils:latest
        imagePullPolicy: Never

Start the pod kubectl apply -f deployment.yml

And then access the shell kubectl exec -it networkutils -- /bin/sh

Upvotes: 1

Blender Fox
Blender Fox

Reputation: 5625

Additional to @gohm'c's answer, you could also try uusing Alpine Linux and either make your own image that has curl installed, or use apk add curl in the pod to install it.

Example pod with alpine:

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: front
  name: front
spec:
  containers:
  - image: alpine
    name: front
    command:
    - /bin/sh
    - -c
    - sleep 1d

Upvotes: 2

gohm'c
gohm'c

Reputation: 15480

busybox is a single binary program which you can't install additional program to it. You can either use wget or you can use a different variant of busybox like progrium which come with a package manager that allows you to do opkg-install curl.

Upvotes: 1

Related Questions