Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there possible to install curl into busybox in kubernetes pod

I am using busybox to detect my network problem in kubernetes v1.18 pods. I created the busybox like this:

apiVersion: v1
kind: Pod
metadata:
    name: busybox
    namespace: default
spec:
    containers:
    - name: busybox
    image: busybox:1.28
    command:
        - sleep
        - "3600"
    imagePullPolicy: IfNotPresent
    restartPolicy: Always

and login to find the kubernetes clusters network situation:

 kubectl exec -it busybox /bin/bash

What surprises me is that the busybox does not contain curl. Why does the busybox package not include the curl command? I am searching the internet and find the docs do not talk about how to add curl into busybox. I tried to install curl, but found no way to do this. Is there anyway to add curl package into busybox?

like image 433
Dolphin Avatar asked Jul 11 '20 09:07

Dolphin


People also ask

Does busybox have cURL?

Busybox is one of the other well-known “box of tools” type images. It doesn't contain curl, but it does contain wget! (It's a travesty, if you ask us.)

How do I run a cURL command inside a pod?

You can execute the curl command inside one of your existing pods through the kubectl exec command. The kubectl exec command allows you to remotely run arbitrary commands inside an existing container of a pod. This comes in handy when you want to examine the contents, state, and/or environment of a container.

How do I run busybox in Kubernetes?

To do so, run and ssh in a busybox minimal bare operating system in a single command ` kubectl run --generator=run-pod/v1 -i --tty busybox --image=busybox --restart=Never -- sh `. It contains several useful tools for debugging. If you don't see a command prompt, try pressing enter.

What is cURL command in Kubernetes?

The command-line tool cURL or Curl, which refers to client URL, is used by developers to transport data to and from a server. At its most basic level, Curl allows you to communicate with a server by defining the destination in the form of a URL and the data you wish to transmit.


Video Answer


5 Answers

The short answer, is you cannot.

Why?

Because busybox does not have package manager like: yum, apk, or apt-get ..

Acutally you have two solutions:

1. Either use a modified busybox

You can use other busybox images like progrium/busybox which provides opkg-install as a package manager.

image: progrium/busybox

Then:

kubectl exec -it busybox -- opkg-install curl

2. Or if your concern to use a minimal image, you can use alpine

image: alpine:3.12

then:

kubectl exec -it alpine -- apk --update add curl
like image 175
Abdennour TOUMI Avatar answered Oct 16 '22 11:10

Abdennour TOUMI


No. Consider alpine as a base image instead that includes BusyBox plus a package manager, or building (or finding) a custom image that has the tools you need pre-installed.

BusyBox is built as a single binary that contains implementations of many common Linux tools. The BusyBox documentation includes a listing of the included commands. You cannot "install" more commands into it without writing C code.

BusyBox does contain an implementation of wget, which might work for your purposes (wget -O- http://other-service).

like image 12
David Maze Avatar answered Oct 16 '22 10:10

David Maze


BusyBox has a subset of wget. The usage patterns of curl are significantly more complex in your OS than the one that comes with Busybox.

To clarify what I mean, run the following in your OS:

$ wget --help | wc -l
207

while running wget's help inside Busybox container should give you a minimal subset package:

$ docker run --rm busybox wget --help 2>&1 | wc -l
20

In K8s, you could run the following:

$ kubectl run -i --tty --rm busybox --image=busybox -- sh
If you don't see a command prompt, try pressing enter.
/ # wget
BusyBox v1.33.1 (2021-06-07 17:33:50 UTC) multi-call binary.

Usage: wget [-cqS] [--spider] [-O FILE] [-o LOGFILE] [--header 'HEADER: VALUE'] [-Y on/off]
    [--no-check-certificate] [-P DIR] [-U AGENT] [-T SEC] URL...

Retrieve files via HTTP or FTP

    --spider    Only check URL existence: $? is 0 if exists
    --no-check-certificate  Don't validate the server's certificate
    -c      Continue retrieval of aborted transfer
    -q      Quiet
    -P DIR      Save to DIR (default .)
    -S          Show server response
    -T SEC      Network read timeout is SEC seconds
    -O FILE     Save to FILE ('-' for stdout)
    -o LOGFILE  Log messages to FILE
    -U STR      Use STR for User-Agent header
    -Y on/off   

If curl is something required for your use case, I wouldsuggest to use Alpine which is busybox + a minimal package manager and libc implementation such that you can trivially do apk add --no-cache curl and get real curl (or even apk add --no-cache wget to get the "real" wget instead of BusyBox's wget).

like image 4
Muhammad Soliman Avatar answered Oct 16 '22 12:10

Muhammad Soliman


As @abdennour is suggesting, I'm no longer sticking with busybox anymore. Alpine is a very lightweight Linux container image as others suggest here in which you can literally install any UNIX-like tool handy to accomplish your troubleshooting task. In fact, I use this function within my dotfiles at .bashrc to spin a handy ephemeral ready-to-rock Alpine pod:

## This function takes an optional argument to run a pod within a Kubernetes NS, if it's not provided it fallsback to `default` NS.
function kalpinepod () { kubectl run -it --rm --restart=Never --image=alpine handytools -n ${1:-default} -- /bin/ash }

❯ kalpinepod kube-system
If you don't see a command prompt, try pressing enter.
/ # cat /etc/resolv.conf
search kube-system.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.245.0.10
options ndots:5
/ # apk --update add curl openssl
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
(1/6) Installing ca-certificates (20191127-r5)
(2/6) Installing brotli-libs (1.0.9-r3)
(3/6) Installing nghttp2-libs (1.42.0-r1)
(4/6) Installing libcurl (7.74.0-r1)
(5/6) Installing curl (7.74.0-r1)
(6/6) Installing openssl (1.1.1j-r0)
Executing busybox-1.32.1-r3.trigger
Executing ca-certificates-20191127-r5.trigger
OK: 9 MiB in 20 packages
like image 3
Marcos Soutullo Avatar answered Oct 16 '22 10:10

Marcos Soutullo


Radial has an overlay of busybox images adding cURL. docker pull radial/busyboxplus:curl

They also have a second images having cURL + Git. docker pull radial/busyboxplus:git

like image 1
mpc-DT Avatar answered Oct 16 '22 11:10

mpc-DT