Skip to content

Instantly share code, notes, and snippets.

@mak3r
Created August 20, 2018 20:11
Show Gist options
  • Save mak3r/9b5ce620fbe7bbfc235f5ccaefacee2b to your computer and use it in GitHub Desktop.
Save mak3r/9b5ce620fbe7bbfc235f5ccaefacee2b to your computer and use it in GitHub Desktop.
Fire up a docker container with a specific kubectl version
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
@mak3r
Copy link
Author

mak3r commented Aug 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment