Reputation: 3128
I'm new to Docker. I'm trying to create a dockerfile which basically sets kubectl (Kubernetes client), helm 3 and Python 3.7. I used:
FROM python:3.7-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app
Now I'm trying to figure out how to add kubectl
and helm
. What would be the best way to install those two?
Upvotes: 1
Views: 18422
Reputation: 3
This works for me
FROM amd64/python:3.11.3-alpine
RUN apk add build-base
RUN apk add curl
# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s
https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN curl -LO "https://dl.k8s.io/$(curl -L -s
https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
RUN install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# Install helm
RUN curl -LO https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz && \
tar -zxvf helm-v3.7.0-linux-amd64.tar.gz && \
mv linux-amd64/helm /usr/local/bin/helm && \
rm -rf helm-v3.7.0-linux-amd64.tar.gz linux-amd64
Upvotes: 0
Reputation: 1
This Dockerfile worked for me with an ubuntu base. I needed kubectl and helm to work with the rest of the deps I had in my docker image
FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install --yes --no-install-recommends ...
RUN curl -LO https://dl.k8s.io/release/v1.24.0/bin/linux/amd64/kubectl && install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
RUN wget https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
chmod 700 get-helm-3 &&\
./get-helm-3
Upvotes: 0
Reputation: 557
Working Dockerfile. This will install the latest and stable versions of kubectl
and helm-3
FROM python:3.7-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app
RUN apk add curl openssl bash --no-cache
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" \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl \
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \
&& chmod +x get_helm.sh && ./get_helm.sh
Upvotes: 15
Reputation: 844
Python should be available from a python base image I guess. My take would be s.th like
ENV K8S_VERSION=v1.18.X
ENV HELM_VERSION=v3.X.Y
ENV HELM_FILENAME=helm-${HELM_VERSION}-linux-amd64.tar.gz
and then in the Dockerfile
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& curl -L https://storage.googleapis.com/kubernetes-helm/${HELM_FILENAME} | tar xz && mv linux-amd64/helm /bin/helm && rm -rf linux-amd64
But be aware of the availability of curl or wget in the baseimage, maybe these or other tools and programs have to be installed before you can use it in the Dockerfile. This always depends on the baseimage used
Upvotes: 1