I want to run 'kubectl' commands in the container, so i want to install kubectl in the container, through while building the Docker image. Any help is appreciated!
Use the kubectl commandThe kubectl binary is not automatically packaged with Docker Desktop for Linux. To install the kubectl command for Linux, see Kubernetes documentation. It should be installed at /usr/local/bin/kubectl .
Can Kubernetes Run Without Docker? The answer is both yes and no. Kubernetes, in itself, is not a complete solution. It depends on a container runtime to orchestrate; you can't manage containers without having containers in the first place.
kubectl
is written in go, so is completely self-contained.
You can therefore copy it from another container that already includes it. Like I do here, copying it from bitnami/kubectl:1.20.9
:
FROM bitnami/kubectl:1.20.9 as kubectl
FROM ubuntu-or-whatever-image:tag
# Do whatever you need to with the
# ubuntu-or-whatever-image:tag image, then:
COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/
I like this better than fiddling with curl
, because now you're taking advantage of Dockers ability to cache the bitnami/kubectl:1.20.9
image.
put this in your Dockerfile
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With