├── .github └── workflows │ └── dockerimage.yml ├── Dockerfile ├── LICENSE ├── Makefile └── README.md /.github/workflows/dockerimage.yml: -------------------------------------------------------------------------------- 1 | name: Build and Publish kubectl container 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | permissions: 13 | id-token: write 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Build and test kubectl container 18 | run: | 19 | GIT_BRANCH=${GITHUB_REF#refs/heads/} make docker_build 20 | GIT_BRANCH=${GITHUB_REF#refs/heads/} make test 21 | - name: Docker meta 22 | if: ${{ startsWith(github.ref, 'refs/heads/m') || startsWith(github.ref, 'refs/heads/v') }} 23 | id: docker_meta 24 | uses: crazy-max/ghaction-docker-meta@v1 25 | with: 26 | images: lachlanevenson/k8s-kubectl 27 | tag-semver: | 28 | {{raw}} 29 | - name: Set up QEMU 30 | if: ${{ startsWith(github.ref, 'refs/heads/m') || startsWith(github.ref, 'refs/heads/v') }} 31 | uses: docker/setup-qemu-action@v1 32 | - name: Set up Docker Buildx 33 | if: ${{ startsWith(github.ref, 'refs/heads/m') || startsWith(github.ref, 'refs/heads/v') }} 34 | uses: docker/setup-buildx-action@v1 35 | - name: install cosign 36 | uses: sigstore/cosign-installer@main 37 | with: 38 | cosign-release: 'v1.13.1' 39 | - name: Login to DockerHub 40 | if: ${{ startsWith(github.ref, 'refs/heads/m') || startsWith(github.ref, 'refs/heads/v') }} 41 | uses: docker/login-action@v1 42 | with: 43 | username: ${{ secrets.DOCKER_USERNAME }} 44 | password: ${{ secrets.DOCKER_PASSWORD }} 45 | - name: Build and publish multi-arch kubectl container 46 | if: ${{ startsWith(github.ref, 'refs/heads/m') || startsWith(github.ref, 'refs/heads/v') }} 47 | uses: docker/build-push-action@v2 48 | with: 49 | platforms: linux/amd64,linux/s390x,linux/arm64,linux/ppc64le 50 | push: true 51 | tags: | 52 | ${{ github.ref != 'refs/heads/main' && steps.docker_meta.outputs.tags || '' }} 53 | ${{ github.ref == 'refs/heads/main' && 'lachlanevenson/k8s-kubectl:latest' || '' }} 54 | labels: ${{ steps.docker_meta.outputs.labels }} 55 | - name: Sign image only on version branches 56 | if: ${{ startsWith(github.ref, 'refs/heads/v') }} 57 | run: cosign sign --oidc-issuer https://token.actions.githubusercontent.com ${TAGS} 58 | env: 59 | TAGS: ${{ steps.docker_meta.outputs.tags }} 60 | COSIGN_EXPERIMENTAL: 1 61 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | LABEL maintainer="Lachlan Evenson " 4 | 5 | ARG VCS_REF 6 | ARG BUILD_DATE 7 | 8 | # Metadata 9 | LABEL org.label-schema.vcs-ref=$VCS_REF \ 10 | org.label-schema.vcs-url="https://github.com/lachie83/k8s-kubectl" \ 11 | org.label-schema.build-date=$BUILD_DATE \ 12 | org.label-schema.docker.dockerfile="/Dockerfile" 13 | 14 | ENV KUBE_LATEST_VERSION="v1.25.4" 15 | 16 | RUN apk add --update ca-certificates \ 17 | && apk add -t deps \ 18 | && apk add --update curl \ 19 | && export ARCH="$(uname -m)" && if [[ ${ARCH} == "x86_64" ]]; then export ARCH="amd64"; elif [[ ${ARCH} == "aarch64" ]]; then export ARCH="arm64"; fi && curl -L https://dl.k8s.io/release/${KUBE_LATEST_VERSION}/bin/linux/${ARCH}/kubectl -o /usr/local/bin/kubectl \ 20 | && chmod +x /usr/local/bin/kubectl \ 21 | && apk del --purge deps \ 22 | && rm /var/cache/apk/* 23 | 24 | WORKDIR /root 25 | ENTRYPOINT ["kubectl"] 26 | CMD ["help"] 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Lachlan Evenson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: docker_build 2 | 3 | DOCKER_IMAGE ?= lachlanevenson/k8s-kubectl 4 | GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) 5 | 6 | ifeq ($(GIT_BRANCH), main) 7 | DOCKER_TAG = latest 8 | else 9 | DOCKER_TAG = $(GIT_BRANCH) 10 | endif 11 | 12 | docker_build: 13 | @docker build \ 14 | --build-arg VCS_REF=`git rev-parse --short HEAD` \ 15 | --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ 16 | -t $(DOCKER_IMAGE):$(DOCKER_TAG) . 17 | 18 | docker_push: 19 | # Push to DockerHub 20 | docker push $(DOCKER_IMAGE):$(DOCKER_TAG) 21 | 22 | test: 23 | docker run $(DOCKER_IMAGE):$(DOCKER_TAG) version --client 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Client 2 | 3 | ### Build GitHub Action Status 4 | ![Build and Publish kubectl container](https://github.com/lachie83/k8s-kubectl/workflows/Build%20and%20Publish%20kubectl%20container/badge.svg) 5 | 6 | ### Container Details 7 | [![](https://images.microbadger.com/badges/image/lachlanevenson/k8s-kubectl.svg)](http://microbadger.com/images/lachlanevenson/k8s-kubectl "Get your own image badge on microbadger.com") 8 | [![](https://images.microbadger.com/badges/version/lachlanevenson/k8s-kubectl.svg)](http://microbadger.com/images/lachlanevenson/k8s-kubectl "Get your own version badge on microbadger.com") 9 | [![](https://images.microbadger.com/badges/commit/lachlanevenson/k8s-kubectl.svg)](http://microbadger.com/images/lachlanevenson/k8s-kubectl "Get your own commit badge on microbadger.com") 10 | 11 | # Supported tags and respective `Dockerfile` links 12 | * `v1.25.4`, `latest` [(v1.25.4/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.25.4/Dockerfile) 13 | * `v1.24.8`, [(v1.24.8/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.24.8/Dockerfile) 14 | * `v1.23.14`, [(v1.23.14/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.23.14/Dockerfile) 15 | * `v1.22.16`, [(v1.22.16/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.22.16/Dockerfile) 16 | * `v1.21.12`, [(v1.21.12/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.21.12/Dockerfile) 17 | * `v1.20.15`, [(v1.20.15/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.20.15/Dockerfile) 18 | * `v1.19.16`, [(v1.19.16/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.19.16/Dockerfile) 19 | * `v1.18.20`, [(v1.18.20/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.18.20/Dockerfile) 20 | * `v1.17.17`, [(v1.17.17/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.17.17/Dockerfile) 21 | * `v1.16.14`, [(v1.16.14/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.16.14/Dockerfile) 22 | * `v1.15.12`, [(v1.15.12/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.15.12/Dockerfile) 23 | * `v1.14.10`, [(v1.14.10/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.14.10/Dockerfile) 24 | * `v1.13.12`, [(v1.13.12/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.13.12/Dockerfile) 25 | * `v1.12.10`, [(v1.12.10/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.12.10/Dockerfile) 26 | * `v1.11.9`, [(v1.11.9/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.11.9/Dockerfile) 27 | * `v1.10.12`, [(v1.10.12/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.10.12/Dockerfile) 28 | * `v1.9.10`, [(v1.9.10/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.9.10/Dockerfile) 29 | * `v1.8.15`, [(v1.8.15/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.8.15/Dockerfile) 30 | * `v1.7.16` [(v1.7.16/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.7.16/Dockerfile) 31 | * `v1.6.13`, [(v1.6.13/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.6.13/Dockerfile) 32 | * `v1.5.8`, [(v1.5.8/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.5.8/Dockerfile) 33 | * `v1.4.12`, [(v1.4.12/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.4.12/Dockerfile) 34 | * `v1.3.10`, [(v1.3.10/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.3.10/Dockerfile) 35 | * `v1.2.6`, [(v1.2.6/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.2.6/Dockerfile) 36 | * `v1.1.8`, [(v1.1.8/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.1.8/Dockerfile) 37 | * `v1.0.7`, [(v1.0.7/Dockerfile)](https://github.com/lachie83/k8s-kubectl/blob/v1.0.7/Dockerfile) 38 | 39 | ## Overview 40 | This container provides the Kubernetes client kubectl which can be used to interact with a Kubernetes cluster. 41 | 42 | ## Supported OS/ARCH 43 | * linux/amd64 44 | * linux/arm64 45 | * linux/s390x 46 | * linux/ppc64le 47 | 48 | Massive thanks to [barthy1](https://github.com/barthy1) via [PR](https://github.com/lachie83/k8s-helm/pull/89) for contributing this work. 49 | 50 | ## Build 51 | `make docker_build` 52 | 53 | ## Run 54 | `docker run --rm lachlanevenson/k8s-kubectl:``git rev-parse --abbrev-ref HEAD`` --server=http://:8080 get pods` 55 | 56 | ## Data Container 57 | 58 | In order to get kube spec files accessible via the kubectl container please use the following data container that exposes a data volume under /data. It dumps everything under cwd in the data container. 59 | 60 | ``` 61 | cat ~/bin/mk-data-container 62 | #!/usr/bin/env sh 63 | 64 | WORKDIR="$1" 65 | 66 | if [ -z $WORKDIR ]; then 67 | WORKDIR='.' 68 | fi 69 | 70 | cd $WORKDIR 71 | echo "FROM debian:jessie\n\nVOLUME [ '/data' ]\n\nCOPY * /data/" > ./Dockerfile.data-container 72 | docker rm data 73 | docker build -f ./Dockerfile.data-container -t temp/data . 74 | docker run --name data temp/data 75 | rm ./Dockerfile.data-container 76 | ``` 77 | 78 | ## Data container with kubectl container 79 | ``` 80 | docker run --rm -it --volumes-from data k8s/kubectl: --server=http://:8080 create -f /data/controller.yml 81 | ``` 82 | 83 | --------------------------------------------------------------------------------