Skip to content
Kubernetes prompt
Go Ruby Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Add github actions Oct 23, 2019
cmd/kubeprompt
imgs Update readme Oct 25, 2019
pkg Improve signal management Nov 11, 2019
.gitignore New structure Oct 25, 2019
.goreleaser.yml Add github actions Oct 23, 2019
LICENSE Add github actions Oct 23, 2019
Makefile Cleanup Oct 25, 2019
README.md Update README Nov 5, 2019
go.mod Update structure Oct 25, 2019
go.sum Update structure Oct 25, 2019
justfile Cleanup Oct 25, 2019
kubeprompt.rb Brew formula update for kubeprompt version 0.1.1 Nov 11, 2019

README.md

kubeprompt

Show information about your current kubernetes context

prompt

Installing

Download it from the releases page or build it locally running make build

Usage

kubeprompt is shell-agnostic and thus works on any shell, but every shell has a different way to customize its prompt. Some examples:

fish shell:

function fish_prompt
  echo (kubeprompt -p) '>'
end

Zsh:

PROMPT='$(kubeprompt -p)'$PROMPT

Bash:

PS1="[\u@\h \W \$(kubeprompt -p)]\$ "

kubeprompt will print to stdout information about the current cluster, but first it needs to be enabled. It is considered enabled if the environment variable KUBECONFIG is set to a file in the $TMP/kubeprompt directory. To enable it, just execute kubeprompt.

kubeprompt command will print the current K8S context and namespace, if kubeprompt is enabled. If not, it will start a sub shell with kubeprompt enabled. The sub shell to launch depends on the value of the environment variable SHELL, starting a bash shell if is not defined.

Valid flags:

  • -p, --print-only print context information only kubeprompt is enabled, don't do anything if not
  • -f, --force print without checking if kubeprompt is enabled
  • -m, --monochrome disables colors in output
  • -c, --check print information about kubeprompt status
  • -h, --help help for kubeprompt
  • -v, --version print the version

Workflows

There are 2 possible workflows

Show information only after enable it

In this case, you call kubeprompt -p in your dot files. To display information about the current kubernetes context, you must call kubeprompt manually to enable it. One advange with this aproach is that you can we confident about the information in your terminal, since every terminal will have its own kubeconfig.

Always show information

In this case, you call kubeprompt -f in your dot files. The advantage here is that you don't need to enable kubeprompt manually, and the information will be always in your prompt. But you cannot know for sure if the information is accurate. Since your kubeconfig is global, other applications (or yourself in other terminal) can change the global kubernetes context.

F.A.Q.

Why to copy kubeconfig and start a sub shell?

If you are working with multiple contexts/namespaces in multiple terminals, all of them will modify the same kubeconfig file when you update the context/namespace. For more context, see kubernetes PR #60044

Let's suppose that you are working in 2 terminals with kubectl in context foo. Since you are using kubeprompt, your prompt shows that the context is foo. Now, you change the context in one terminal to bar, and after it you change the focus to the other terminal. Since the prompt information is static, in that terminal the prompt still says that the context is foo, but that information is old, and you could execute a command in the wrong context.

To avoid it, kubepromt creates a copy of your current kubeconfig per terminal and sets the KUBECONFIG environment variable to that copy. If now you change the context or the namespace, only that terminal will be affected. If you want to disable kubeprompt on one terminal, you just need to press CTRL+d

Related tools

You can’t perform that action at this time.