Skip to content

unwired/kubectl-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubectl with auto-completion in a docker container

The purpose of this tool is to have a fully portable kubectl command line tool with a few convinience utilities. Quick testing of a cluster with well-known/customized kubectl setup.

What is included

There are two images, one simple image with bash shell containing:

  • kubectl - Kuberneted CLI v 1.17.2 with bash completion
  • k9s - cluster monitoring tool
  • popular tools: curl, wget, git
  • useful aliases

Use this image if you want to quickly check and explore Kubernetes cluster without investing too much time. This image is optimized for size performance.

And one is a fancy image for zsh with more tools preinstalled:

  • kubectl - Kubernetes CLI v 1.17.2 with zsh completion
  • zsh-autosuggestions - very useful zsh shell plugin showing previous commands and enabling easy autofill of text
  • helm - Kubernetes package manager
  • okteto - development platform for Kubernetes applications
  • k9s - cluster monitoring tool
  • krew - Kubernetes plugin manager
  • tmux based on highly customized, great repo from samoshkin
  • popular tools: curl, wget, git
  • useful aliases

Use this image if you want to monitor and develop for Kubernetes. This is my default image with all favourite tools and settings. This image is optimized for usability.

How to use

After running docker container, all the clusters running on the localhost should be available for kubectl command.

Aliases

Make use of aliases defined for both shells bash and zsh

Instead of typing kubectl all the time, abbreviate it to just “k”

alias k=kubectl

Check what is running on the cluster

alias kdump='kubectl get all --all-namespaces'

Display helpful info for creating k8s resources imperatively

alias krun='k run -h | grep “# “ -A2'

Quickly spin up busybox pod for diagnostic purposes

alias kdiag='kubectl run -it --rm debug --image=busybox --restart=Never -- sh'

Supported tags

  • zsh docker pull piotrzan/kubectl-comp:zsh Dockerfile

  • bash docker pull piotrzan/kubectl-comp Dockerfile

How the images are build

Build image with bash shell

docker build --rm -f "Dockerfile" -t piotrzan/kubectl-comp "."

Build image with zsh shell

docker build --rm -f "Dockerfile" -t piotrzan/kubectl-comp:zsh "."

Convinient scripts to run the contianer

Use run.ps1 or run.sh for windows or linux respectivels. Alternatively use docker-compose.yaml, this works by mounting a volume on the $HOME/.kube folder on the host.

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.

ZSH container will be ran by default.

Linux Example

Below is also the default for make command.

Run contianer with passthrough to local network

docker run -d --network=host --name=kubectl-host --rm -it piotrzan/kubectl-comp

Generate raw config from kubeclt on localhost and copy the config to the container

kubeclt config view --raw > config
docker cp ./config kubectl-host:./root/.kube

Attach back to the contianer with kubeconfig file containing info about clusters running on localhost

docker attach kubectl-host

Extending the image

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.

docker commit $(docker ps -aqf "name=kubectl-host") piotrzan/kubectl-comp:zsh - this captures contianer kubectl-host as a new tag docker push piotrzan/kubectl-comp:zsh

About

kubectl with plugins and auto-completion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 61.5%
  • Dockerfile 26.3%
  • Makefile 7.4%
  • PowerShell 4.8%