Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active January 19, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhenakh/e91e96a6530e9305f0b5a43c51a8a407 to your computer and use it in GitHub Desktop.
Save akhenakh/e91e96a6530e9305f0b5a43c51a8a407 to your computer and use it in GitHub Desktop.
Nice shell for kubernetes

Tools

Install required tools

brew install fzf
brew install kubectx
brew install stern
brew install kube-ps1
brew install kubecolor/tap/kubecolor
brew install kubernetes-cli
brew install octant

Change your shell into zsh (should be the case since High Sierra)

chsh -s /bin/zsh

Install oh my zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

NOTE: the installer will rename an existing .zshrc file to .zshrc.pre-oh-my-zsh.

Enable some plugins in your .zshrc (look for plugins)

plugins=(brew kubectl git python zsh-completions)

Add these lines at the end of your .zshrc

source <(stern --completion=zsh)
alias kubectl=kubecolor
# make completion work with kubecolor
compdef kubecolor=kubectl

Displaying the current Kubernetes context

Add this to the end of your .zshrc

KUBE_PS1_PREFIX=""
KUBE_PS1_SUFFIX=""
KUBE_PS1_SYMBOL_ENABLE=false
source "/opt/homebrew/opt/kube-ps1/share/kube-ps1.sh"
RPROMPT='$(kube_ps1) %{$fg[green]%}[%*]%{$reset_color%}'

Theme

This theme is a 2 lines theme giving you space to type:

ZSH_THEME="tjkirch"

Using it

You can then switch context with kubectx.

kubectl is aliased to k, type k get po <tab>

Use everywhere you want completion on any Kubernetes attributes, works with the CRD as well: k get <tab> will show you all CRDs.

To tail the logs for all pods of the same deployment stern auth-gen -n auth-generator-api --since 1m.

For a web experience to the cluster use octant.

Links

More tools https://cloud-native-canada.github.io/k8s_setup_tools/

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