Created
August 20, 2018 20:11
-
-
Save mak3r/9b5ce620fbe7bbfc235f5ccaefacee2b to your computer and use it in GitHub Desktop.
Fire up a docker container with a specific kubectl version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:18.04 | |
# default kubectl version is current stable | |
# override this when building the container to use a different version | |
ARG KUBECTL_VER='$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)' | |
WORKDIR /app | |
# include my kubeconfig in the container | |
COPY kubeconfig /app/kubeconfig | |
ENV KUBECONFIG /app/kubeconfig | |
# update apt | |
RUN apt-get update -y | |
# install curl | |
RUN apt-get install -y curl | |
# put the kubectl version into a file for later use in the environment | |
RUN bash -c 'echo export VER=${KUBECTL_VER} > /etc/profile.d/k8s-env.sh' | |
# download the version of kubectl specified | |
RUN bash -c 'source /etc/profile.d/k8s-env.sh; curl -LO https://storage.googleapis.com/kubernetes-release/release/$VER/bin/linux/amd64/kubectl' | |
RUN chmod +x ./kubectl | |
RUN mv ./kubectl /usr/local/bin/kubectl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put your kubeconfig file in the directory you run this docker build from and it will get added to the /app dir in the container
The default is to grab the current kubectl version
Add a --build-arg to the command line to specify a version
docker build --build-arg KUBECTL_VER=v1.9.7 -t kubectl-v1.9.7 .
Get in there and use it
docker run -it kubectl-v1.9.7 /bin/bash