Kubernetes Context in iTerm2's Status Bar
This project is maintained by siggy
This guide demonstrates displaying the current Kubernetes context in iTerm2’s Status Bar.
Note: This requires iTerm2 3.3+.

iTerm2 > Install Shell Integration
This will add a line to your .bash_profile:
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
kubecontext user variableBefore .iterm2_shell_integration.bash is loaded, add this function:
function iterm2_print_user_vars() {
iterm2_set_user_var kubecontext $(kubectl config current-context)
}
The above command can be slow if the internet connection is slow. An alternative is to use this function:
function iterm2_print_user_vars() {
iterm2_set_user_var kubecontext $(awk '/^current-context:/{print $2;exit;}' <~/.kube/config)
}
If you want to display the current namespace in your Status Bar as well, add this function instead:
function iterm2_print_user_vars() {
iterm2_set_user_var kubecontext $(kubectl config current-context):$(kubectl config view --minify --output 'jsonpath={..namespace}')
}
kubecontext Status Bar componentiTerm2 > Preferences > Profiles > Session > Configure Status BarInterpolated String component to Active Components.Configure Component.String Value to \(user.kubecontext)