├── .gitignore ├── bash ├── .bash_profile ├── docker-compose.yaml ├── bootstrap.sh ├── run.ps1 ├── run.sh ├── Dockerfile └── .bashrc ├── zsh ├── docker-compose.yaml ├── run.sh ├── run.ps1 ├── Dockerfile └── .zshrc ├── .dockerignore ├── .github ├── renovate.json └── workflows │ ├── build_push_bash.yml │ └── build_push_zsh.yml ├── Makefile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | **/*config 2 | .ionide/* 3 | bash/.ionide/symbolCache.db 4 | -------------------------------------------------------------------------------- /bash/.bash_profile: -------------------------------------------------------------------------------- 1 | if [ -f /etc/bash_completion ]; then 2 | . /etc/bash_completion 3 | fi -------------------------------------------------------------------------------- /bash/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | kubectl-host: 4 | image: piotrzan/kubectl-comp 5 | container_name: kubectl-host 6 | tty: true 7 | network_mode: "host" 8 | volumes: 9 | - ~/.kube/:/root/.kube/ 10 | command: "/bin/sh" -------------------------------------------------------------------------------- /zsh/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | kubectl-host: 4 | image: piotrzan/kubectl-comp:zsh 5 | container_name: kubectl-host 6 | tty: true 7 | network_mode: "host" 8 | volumes: 9 | - ~/.kube/:/root/.kube/ 10 | entrypoint: "/bin/zsh" -------------------------------------------------------------------------------- /bash/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir /root/.kube 4 | 5 | echo "source <(kubectl completion bash)" >> ~/.bashrcource <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first. \ 6 | 7 | # Add krew to path to call it from kubectl 8 | source ~/.bashrc -------------------------------------------------------------------------------- /bash/run.ps1: -------------------------------------------------------------------------------- 1 | # Run contianer with passthrough to local network 2 | docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp 3 | 4 | # Generate raw config from kubeclt on localhost and copy the config to the container 5 | kubectl config view --raw > config 6 | docker cp config kubectl-host:./root/.kube 7 | 8 | docker attach kubectl-host -------------------------------------------------------------------------------- /bash/run.sh: -------------------------------------------------------------------------------- 1 | # Run contianer with passthrough to local network 2 | docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp 3 | 4 | # Generate raw config from kubeclt on localhost and copy the config to the container 5 | kubectl config view --raw > config 6 | docker cp config kubectl-host:./root/.kube 7 | 8 | docker attach kubectl-host -------------------------------------------------------------------------------- /zsh/run.sh: -------------------------------------------------------------------------------- 1 | # Run contianer with passthrough to local network 2 | docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp:zsh 3 | 4 | # Generate raw config from kubeclt on localhost and copy the config to the container 5 | kubectl config view --raw > config 6 | docker cp config kubectl-host:./root/.kube 7 | 8 | docker attach kubectl-host -------------------------------------------------------------------------------- /zsh/run.ps1: -------------------------------------------------------------------------------- 1 | # Run contianer with passthrough to local network 2 | docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp:zsh 3 | 4 | # Generate raw config from kubeclt on localhost and copy the config to the container 5 | kubectl config view --raw > config 6 | docker cp config kubectl-host:./root/.kube 7 | 8 | docker attach kubectl-host -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | **/.ionide 25 | README.md -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base"], 3 | "labels": ["renovate"], 4 | "regexManagers": [ 5 | { 6 | "fileMatch": ["^Makefile$"], 7 | "matchStrings": [ 8 | "#\\s*renovate:\\s*datasource=(?.*?)\\s+depName=(?.*?)(\\s+versioning=(?.*?))?(\\s+registry=(?.*?))?\\s.*?_VERSION\\s+[^=]?=\\s+(?.*)\\s" 9 | ], 10 | "versioningTemplate": "{{#if versioning}}{{{versioning}}}{{else}}semver{{/if}}" 11 | }, 12 | { 13 | "fileMatch": ["(^|/|\\.)Dockerfile$", "(^|/)Dockerfile[^/]*$"], 14 | "matchStrings": [ 15 | "#\\s*renovate:\\s*datasource=(?.*?)\\s+depName=(?.*?)(\\s+versioning=(?.*?))?(\\s+registry=(?.*?))?\\sARG\\s+.*?_VERSION=(?.*)\\s" 16 | ], 17 | "versioningTemplate": "{{#if versioning}}{{{versioning}}}{{else}}semver{{/if}}" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /bash/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3 as stage 2 | LABEL maintainer="Piotr Zaniewski " 3 | 4 | ARG KUBECTL_VERSION="v1.20.0" 5 | ENV ENV_KUBECTL_VERSION=${KUBECTL_VERSION} 6 | 7 | WORKDIR /root 8 | 9 | COPY .bashrc .bash_profile bootstrap.sh ./ 10 | 11 | ADD https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl /usr/local/bin/kubectl 12 | 13 | RUN apk add --no-cache \ 14 | bash-completion \ 15 | ca-certificates \ 16 | && rm -rf /var/lib/apt/lists/* 17 | 18 | # Bootstrap kubectl 19 | RUN set -x && \ 20 | apk add --no-cache curl ca-certificates && \ 21 | chmod +x /usr/local/bin/kubectl && \ 22 | kubectl version --client 23 | 24 | FROM alpine:3 as app 25 | 26 | WORKDIR /root 27 | 28 | RUN mkdir /root/.kube \ 29 | && rm -rf /var/lib/apt/lists/* 30 | 31 | RUN /bin/sh -c "apk add --no-cache bash" 32 | 33 | COPY --from=stage ["/usr/local/bin/kubectl", "/usr/local/bin/"] 34 | 35 | COPY .bashrc .bash_profile ./ 36 | 37 | ENTRYPOINT ["/bin/bash"] -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | IMAGE?=piotrzan/kubectl-comp:zsh 2 | #piotrzan/kubectl-comp:zsh 3 | #piotrzan/kubectl-comp 4 | 5 | .PHONY: all run-detatch-zsh run-zsh run-detatch-bash run-bash copy attach zsh-run bash-run run-with-mount run-with-mount-k8s-labs 6 | 7 | default: run-with-mount 8 | 9 | run-with-mount: 10 | ifeq ($(OS),Windows_NT) 11 | docker run --network=host --name=kubectl-host -v ${USERPROFILE}/.kube:/root/.kube --rm -it $(IMAGE) 12 | else 13 | docker run --network=host --name=kubectl-host -v /root/.kube:/root/.kube --rm -it $(IMAGE) 14 | endif 15 | 16 | run-with-mount-k8s-labs: 17 | # This is used to run image on https://labs.play-with-k8s.com/ 18 | docker run --network=host --name=kubectl-host -v /etc/kubernetes/admin.conf:/root/.kube/config --rm -it $(IMAGE) 19 | 20 | run-detatch-zsh: 21 | docker run -d --network=host --name=kubectl-host --rm -it $(IMAGE) 22 | 23 | run-zsh: 24 | docker run --network=host --name=kubectl-host 25 | 26 | copy: 27 | kubectl config view --raw > config 28 | docker cp config kubectl-host:./root/.kube 29 | 30 | attach: 31 | docker attach kubectl-host 32 | 33 | zsh-run: run-detatch-zsh copy attach -------------------------------------------------------------------------------- /.github/workflows/build_push_bash.yml: -------------------------------------------------------------------------------- 1 | name: Build and deploy bash version to Docker Hub. 2 | 3 | # Controls when the action will run. 4 | on: 5 | # Triggers the workflow on push or pull request events but only for the master branch 6 | push: 7 | branches: [ master ] 8 | pull_request: 9 | branches: [ master ] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | build: 18 | # The type of runner that the job will run on 19 | runs-on: ubuntu-latest 20 | 21 | # Steps represent a sequence of tasks that will be executed as part of the job 22 | steps: 23 | - name: Set up QEMU 24 | uses: docker/setup-qemu-action@v2 25 | 26 | - name: Set up Docker Buildx 27 | uses: docker/setup-buildx-action@v2 28 | 29 | - name: Login to DockerHub 30 | uses: docker/login-action@v2 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKER_HUB_PW }} 34 | 35 | - name: Build and push 36 | id: docker_build 37 | uses: docker/build-push-action@v3.2.0 38 | with: 39 | context: "{{defaultContext}}:bash" 40 | push: true 41 | tags: piotrzan/kubectl-comp:v1.0.0-bash 42 | 43 | - name: Image digest 44 | run: echo ${{ steps.docker_build.outputs.digest }} 45 | -------------------------------------------------------------------------------- /.github/workflows/build_push_zsh.yml: -------------------------------------------------------------------------------- 1 | name: Build and deploy zsh version to Docker Hub. 2 | 3 | # Controls when the action will run. 4 | on: 5 | # Triggers the workflow on push or pull request events but only for the master branch 6 | push: 7 | branches: [ master ] 8 | pull_request: 9 | branches: [ master ] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | build: 18 | # The type of runner that the job will run on 19 | runs-on: ubuntu-latest 20 | 21 | # Steps represent a sequence of tasks that will be executed as part of the job 22 | steps: 23 | - name: Set up QEMU 24 | uses: docker/setup-qemu-action@v2 25 | 26 | - name: Set up Docker Buildx 27 | uses: docker/setup-buildx-action@v2 28 | 29 | - name: Login to DockerHub 30 | uses: docker/login-action@v2 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKER_HUB_PW }} 34 | 35 | - name: Build and push 36 | id: docker_build 37 | uses: docker/build-push-action@v3.2.0 38 | with: 39 | context: "{{defaultContext}}:zsh" 40 | push: true 41 | tags: piotrzan/kubectl-comp:v1.0.0-zsh 42 | 43 | - name: Image digest 44 | run: echo ${{ steps.docker_build.outputs.digest }} 45 | -------------------------------------------------------------------------------- /zsh/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:23.10 2 | LABEL maintainer="Piotr Zaniewski " 3 | 4 | WORKDIR /root 5 | ARG TARGETARCH=amd64 6 | 7 | RUN apt-get update && apt-get -y install --no-install-recommends \ 8 | gnupg \ 9 | curl \ 10 | wget \ 11 | git \ 12 | apt-transport-https \ 13 | ca-certificates \ 14 | zsh \ 15 | tmux \ 16 | vim \ 17 | fzf \ 18 | && rm -rf /var/lib/apt/lists/* 19 | 20 | ENV SHELL /usr/bin/zsh 21 | 22 | RUN echo '[STEP 1] Creating directory for kubectl config' && \ 23 | mkdir /root/.kube 24 | 25 | # renovate: datasource=github-releases depName=kubernetes/kubernetes 26 | ARG KUBECTL_VERSION=v1.26.1 27 | RUN echo '[STEP 2] Installing kubectl' && \ 28 | set -x && \ 29 | curl -sLO "https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" && \ 30 | chmod +x kubectl && \ 31 | ./kubectl version --client && \ 32 | mv kubectl /usr/local/bin/ 33 | 34 | # renovate: datasource=github-releases depName=derailed/k9s 35 | ARG K9S_VERSION=v0.26.7 36 | RUN echo '[STEP 3] Installing k9s awesomeness' && \ 37 | set -x && \ 38 | wget -c https://github.com/derailed/k9s/releases/download/"${K9S_VERSION}"/k9s_Linux_x86_64.tar.gz -O - | tar -xz && \ 39 | chmod +x k9s && \ 40 | mv k9s /usr/local/bin/ 41 | 42 | RUN echo '[STEP 4] Installing Oh-My-Zsh' && \ 43 | wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true 44 | 45 | RUN echo '[STEP 5] Installing zsh-autosuggestions plugin' && \ 46 | git clone https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions 47 | 48 | COPY .zshrc ./ 49 | 50 | RUN echo '[STEP 6] Install tmux with cool customizations' && \ 51 | git clone https://github.com/samoshkin/tmux-config.git && \ 52 | ./tmux-config/install.sh 53 | 54 | # renovate: datasource=github-releases depName=kubernetes-sigs/krew 55 | ARG KREW_VERSION=v0.4.3 56 | RUN echo '[STEP 7] Install krew kubectl plugin' \ 57 | set -x && \ 58 | wget https://github.com/kubernetes-sigs/krew/releases/download/"${KREW_VERSION}"/krew-linux_amd64.tar.gz && \ 59 | tar zxvf krew-linux_amd64.tar.gz && \ 60 | ./krew-linux_amd64 install krew 61 | 62 | RUN echo '[STEP 8] Installing stern' && \ 63 | ./krew-linux_amd64 install stern && \ 64 | ./krew-linux_amd64 install ns && \ 65 | ./krew-linux_amd64 install ctx 66 | 67 | # renovate: datasource=github-releases depName=kubernetes-sigs/krew 68 | ARG KUBESEAL_VERSION=0.18.0 69 | RUN echo '[STEP 9] Install kubeseal' && \ 70 | wget https://github.com/bitnami-labs/sealed-secrets/releases/download/v0.18.0/kubeseal-"${KUBESEAL_VERSION}"-linux-amd64.tar.gz && \ 71 | tar -xvf kubeseal-"${KUBESEAL_VERSION}"-linux-amd64.tar.gz && \ 72 | cp kubeseal /usr/local/bin/ 73 | 74 | RUN echo '[STEP 10] Setting zsh as default shell' && \ 75 | chsh -s $(which zsh) 76 | 77 | CMD ["k9s"] 78 | 79 | ENTRYPOINT ["/usr/bin/zsh", "-c"] 80 | -------------------------------------------------------------------------------- /bash/.bashrc: -------------------------------------------------------------------------------- 1 | # ~/.bashrc: executed by bash(1) for non-login shells. 2 | # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) 3 | # for examples 4 | 5 | # If not running interactively, don't do anything 6 | case $- in 7 | *i*) ;; 8 | *) return;; 9 | esac 10 | 11 | # don't put duplicate lines or lines starting with space in the history. 12 | # See bash(1) for more options 13 | HISTCONTROL=ignoreboth 14 | 15 | # append to the history file, don't overwrite it 16 | shopt -s histappend 17 | 18 | # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) 19 | HISTSIZE=1000 20 | HISTFILESIZE=2000 21 | 22 | # check the window size after each command and, if necessary, 23 | # update the values of LINES and COLUMNS. 24 | shopt -s checkwinsize 25 | 26 | # make less more friendly for non-text input files, see lesspipe(1) 27 | [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" 28 | 29 | # set variable identifying the chroot you work in (used in the prompt below) 30 | if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then 31 | debian_chroot=$(cat /etc/debian_chroot) 32 | fi 33 | 34 | # set a fancy prompt (non-color, unless we know we "want" color) 35 | case "$TERM" in 36 | xterm-color|*-256color) color_prompt=yes;; 37 | esac 38 | 39 | # uncomment for a colored prompt, if the terminal has the capability; turned 40 | # off by default to not distract the user: the focus in a terminal window 41 | # should be on the output of commands, not on the prompt 42 | force_color_prompt=yes 43 | 44 | if [ -n "$force_color_prompt" ]; then 45 | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then 46 | # We have color support; assume it's compliant with Ecma-48 47 | # (ISO/IEC-6429). (Lack of such support is extremely rare, and such 48 | # a case would tend to support setf rather than setaf.) 49 | color_prompt=yes 50 | else 51 | color_prompt= 52 | fi 53 | fi 54 | 55 | if [ "$color_prompt" = yes ]; then 56 | PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 57 | else 58 | PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' 59 | fi 60 | unset color_prompt force_color_prompt 61 | 62 | 63 | # enable color support of ls and also add handy aliases 64 | if [ -x /usr/bin/dircolors ]; then 65 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" 66 | alias ls='ls --color=auto' 67 | #alias dir='dir --color=auto' 68 | #alias vdir='vdir --color=auto' 69 | 70 | alias grep='grep --color=auto' 71 | alias fgrep='fgrep --color=auto' 72 | alias egrep='egrep --color=auto' 73 | fi 74 | 75 | # some more ls aliases 76 | alias ll='ls -alF' 77 | alias la='ls -A' 78 | alias l='ls -CF' 79 | 80 | # enable programmable completion features (you don't need to enable 81 | # this, if it's already enabled in /etc/bash.bashrc and /etc/profile 82 | # sources /etc/bash.bashrc). 83 | if ! shopt -oq posix; then 84 | if [ -f /usr/share/bash-completion/bash_completion ]; then 85 | . /usr/share/bash-completion/bash_completion 86 | elif [ -f /etc/bash_completion ]; then 87 | . /etc/bash_completion 88 | fi 89 | fi 90 | 91 | # Kubectl auto-completion and aliases 92 | source <(kubectl completion bash) 93 | alias k=kubectl 94 | complete -F __start_kubectl k 95 | alias kdump='kubectl get all --all-namespaces' 96 | alias krun='k run -h | grep "# " -A2' 97 | alias kdiag='kubectl run -it --rm debug --image=busybox --restart=Never -- sh' 98 | 99 | [ -f ~/.fzf.bash ] && source ~/.fzf.bash 100 | 101 | -------------------------------------------------------------------------------- /zsh/.zshrc: -------------------------------------------------------------------------------- 1 | # If you come from bash you might have to change your $PATH. 2 | # export PATH=$HOME/bin:/usr/local/bin:$PATH 3 | 4 | # Path to your oh-my-zsh installation. 5 | export ZSH="/root/.oh-my-zsh" 6 | 7 | # source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh 8 | 9 | if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi 10 | # Set name of the theme to load --- if set to "random", it will 11 | # load a random theme each time oh-my-zsh is loaded, in which case, 12 | # to know which specific one was loaded, run: echo $RANDOM_THEME 13 | # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 14 | ZSH_THEME="robbyrussell" 15 | 16 | # Set list of themes to pick from when loading at random 17 | # Setting this variable when ZSH_THEME=random will cause zsh to load 18 | # a theme from this variable instead of looking in ~/.oh-my-zsh/themes/ 19 | # If set to an empty array, this variable will have no effect. 20 | # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) 21 | 22 | # Uncomment the following line to use case-sensitive completion. 23 | # CASE_SENSITIVE="true" 24 | 25 | # Uncomment the following line to use hyphen-insensitive completion. 26 | # Case-sensitive completion must be off. _ and - will be interchangeable. 27 | # HYPHEN_INSENSITIVE="true" 28 | 29 | # Uncomment the following line to disable bi-weekly auto-update checks. 30 | # DISABLE_AUTO_UPDATE="true" 31 | 32 | # Uncomment the following line to automatically update without prompting. 33 | # DISABLE_UPDATE_PROMPT="true" 34 | 35 | # Uncomment the following line to change how often to auto-update (in days). 36 | # export UPDATE_ZSH_DAYS=13 37 | 38 | # Uncomment the following line if pasting URLs and other text is messed up. 39 | # DISABLE_MAGIC_FUNCTIONS=true 40 | 41 | # Uncomment the following line to disable colors in ls. 42 | # DISABLE_LS_COLORS="true" 43 | 44 | # Uncomment the following line to disable auto-setting terminal title. 45 | # DISABLE_AUTO_TITLE="true" 46 | 47 | # Uncomment the following line to enable command auto-correction. 48 | # ENABLE_CORRECTION="true" 49 | 50 | # Uncomment the following line to display red dots whilst waiting for completion. 51 | # COMPLETION_WAITING_DOTS="true" 52 | 53 | # Uncomment the following line if you want to disable marking untracked files 54 | # under VCS as dirty. This makes repository status check for large repositories 55 | # much, much faster. 56 | # DISABLE_UNTRACKED_FILES_DIRTY="true" 57 | 58 | # Uncomment the following line if you want to change the command execution time 59 | # stamp shown in the history command output. 60 | # You can set one of the optional three formats: 61 | # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 62 | # or set a custom format using the strftime function format specifications, 63 | # see 'man strftime' for details. 64 | # HIST_STAMPS="mm/dd/yyyy" 65 | 66 | # Would you like to use another custom folder than $ZSH/custom? 67 | # ZSH_CUSTOM=/path/to/new-custom-folder 68 | 69 | # Which plugins would you like to load? 70 | # Standard plugins can be found in ~/.oh-my-zsh/plugins/* 71 | # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 72 | # Example format: plugins=(rails git textmate ruby lighthouse) 73 | # Add wisely, as too many plugins slow down shell startup. 74 | plugins=(git zsh-autosuggestions kubectl) 75 | 76 | source $ZSH/oh-my-zsh.sh 77 | 78 | # User configuration 79 | 80 | # export MANPATH="/usr/local/man:$MANPATH" 81 | 82 | # You may need to manually set your language environment 83 | # export LANG=en_US.UTF-8 84 | 85 | # Preferred editor for local and remote sessions 86 | # if [[ -n $SSH_CONNECTION ]]; then 87 | # export EDITOR='vim' 88 | # else 89 | # export EDITOR='mvim' 90 | # fi 91 | 92 | # Compilation flags 93 | # export ARCHFLAGS="-arch x86_64" 94 | 95 | # Set personal aliases, overriding those provided by oh-my-zsh libs, 96 | # plugins, and themes. Aliases can be placed here, though oh-my-zsh 97 | # users are encouraged to define aliases within the ZSH_CUSTOM folder. 98 | # For a full list of active aliases, run `alias`. 99 | # 100 | # Example aliases 101 | # alias zshconfig="mate ~/.zshrc" 102 | # alias ohmyzsh="mate ~/.oh-my-zsh" 103 | # # My path aliases 104 | alias kdump='kubectl get all --all-namespaces' 105 | alias krun='k run -h | grep "# " -A2' 106 | alias kdiag='kubectl run -it --rm debug --image=busybox --restart=Never -- sh' 107 | alias diskusage='du -sh * | sort -h --reverse' 108 | alias ll='ls -lah' 109 | 110 | eval $(dircolors -p | sed -e 's/DIR 01;34/DIR 01;36/' | dircolors /dev/stdin) 111 | 112 | export KUBECONFIG=$HOME/.kube/config 113 | 114 | PATH=$HOME/.local/bin:$PATH 115 | PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubectl with auto-completion in a docker container 2 | 3 | The purpose of this tool is to have a fully portable `kubectl` command line tool with a few convinience utilities. 4 | Quick testing of a cluster with well-known/customized `kubectl` setup. 5 | 6 | ## What is included 7 | 8 | > to see all the packages installed in both tags, you can use `docker sbom` command 9 | 10 | ```bash 11 | KUBECTL_COMP_VERSION=v1.0.0 12 | docker sbom piotrzan/kubectl-comp:"$KUBECTL_COMP_VERSION"-bash 13 | docker sbom piotrzan/kubectl-comp:"$KUBECTL_COMP_VERSION"-zsh 14 | ``` 15 | 16 | There are two images, one simple image with *bash* shell containing: 17 | 18 | - `kubectl` - latest 19 | > It is easy to override `kubectl` version by using `--build-arg` flag in docker build command 20 | > `docker build --build-arg KUBECTL_VERSION=v1.19.4 --rm -f "Dockerfile" -t piotrzan/kubectl-comp:v1.0.0-bash "."` 21 | - useful aliases 22 | 23 | Use this image if you want to quickly check and explore Kubernetes cluster without investing too much time. 24 | This image is optimized for size performance and is based on ``Apline`` base image and is **16 MB** compressed size. 25 | 26 | And one is a fancy image for *zsh* with more tools preinstalled: 27 | 28 | - `kubectl` - latest 29 | - `zsh-autosuggestions` - very useful zsh shell plugin showing previous commands and enabling easy autofill of text 30 | - `helm` - Kubernetes package manager 31 | - `okteto` - development platform for Kubernetes applications 32 | - `k9s` - cluster monitoring tool 33 | - `kubectx` - easily switch between Kubernetes contexts 34 | - `kubens` - easily switch between Kubernetes namespaces 35 | - `tmux` based on highly customized, [great repo from samoshkin](https://github.com/samoshkin/tmux-config) 36 | - popular tools: `curl, wget, git` 37 | - useful aliases 38 | 39 | Use this image if you want to monitor and develop for Kubernetes. This is my default image with all favourite tools and settings. 40 | This image is optimized for usability and is based on ``Ubuntu`` base image and is **168 MB** compressed size. 41 | 42 | ## How to use 43 | 44 | After running docker container, all the clusters running on the localhost should be available for `kubectl` command. 45 | 46 | ### Aliases 47 | 48 | Make use of aliases defined for both shells *bash* and *zsh* 49 | 50 | __Instead of typing kubectl all the time, abbreviate it to just “k”__ 51 | 52 | alias k=kubectl 53 | 54 | __Check what is running on the cluster__ 55 | 56 | alias kdump='kubectl get all --all-namespaces' 57 | 58 | __Display helpful info for creating k8s resources imperatively__ 59 | 60 | alias krun='k run -h | grep “# “ -A2' 61 | 62 | __Quickly spin up busybox pod for diagnostic purposes__ 63 | 64 | alias kdiag='kubectl run -it --rm debug --image=busybox --restart=Never -- sh' 65 | 66 | ## Supported tags 67 | 68 | - **zsh** 69 | docker pull piotrzan/kubectl-comp:v1.0.0-zsh 70 | [Dockerfile](https://github.com/Piotr1215/kubectl-container/blob/master/zsh/Dockerfile) 71 | 72 | - **bash** 73 | docker pull piotrzan/kubectl-comp:v1.0.0-bash 74 | [Dockerfile](https://github.com/Piotr1215/kubectl-container/blob/master/bash/Dockerfile) 75 | 76 | ## How the images are build 77 | 78 | ### Build image with bash shell 79 | 80 | docker build --rm -f "Dockerfile" -t piotrzan/kubectl-comp:v1.0.0-bash "." 81 | 82 | ### Build image with zsh shell 83 | 84 | docker build --rm -f "Dockerfile" -t piotrzan/kubectl-comp:v1.0.0-zsh "." 85 | 86 | ## Convinient scripts to run the contianer 87 | 88 | Use `run.ps1` or `run.sh` for windows or linux respectivels. 89 | Alternatively use docker-compose.yaml, this works by mounting a volume on the $HOME/.kube folder on the host. 90 | 91 | Another option is running `make` (defaults to content of run script). `Make` can be run from root directory and will run images depending on the tasks. Linux has `make` installed by default, for Windows please install first [Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm). 92 | 93 | ZSH container will be ran by default. 94 | 95 | ### Linux Example 96 | 97 | By default `make` command will run `zsh` container with direct mount on the *($home)/.kube directory*. 98 | 99 | **Run contianer with passthrough to local network** 100 | 101 | docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp:v1.0.0-bash 102 | 103 | **Generate raw config from kubeclt on localhost and copy the config to the container** 104 | 105 | kubectl config view --raw > config 106 | docker cp ./config kubectl-host:./root/.kube 107 | 108 | **Attach back to the contianer with kubeconfig file containing info about clusters running on localhost** 109 | 110 | docker attach kubectl-host 111 | 112 | ## Extending the image 113 | 114 | If you would like to add your own customization, you can easily do it and use `docker commit` to create your own version of the image. 115 | 116 | `docker commit $(docker ps -aqf "name=kubectl-host") piotrzan/kubectl-comp:v1.0.0-zsh` - this captures contianer kubectl-host as a new tag 117 | `docker push piotrzan/kubectl-comp:v1.0.0-zsh` 118 | --------------------------------------------------------------------------------