Display your active Kubernetes cluster and namespace in the terminal prompt so you never accidentally run commands in the wrong environment.
Temporarily hide the Kubernetes prompt with kubeoff when working on unrelated tasks, and bring it back with kubeon.
Customize prompt colors, symbols, and separator characters to match your team's shell configuration style.
Use kube-ps1 with OpenShift clusters by setting one variable to point to the oc CLI instead of kubectl.
Install via Homebrew on Mac or source the script in your shell config file, no additional infrastructure required.
kube-ps1 is a small shell script for people who work with Kubernetes from the command line. When you are managing multiple Kubernetes clusters or environments, it is easy to lose track of which cluster and which namespace you are currently pointed at. This script adds that information directly to your terminal prompt so it is always visible, right before the cursor where you type commands. The prompt it adds shows a symbol (a nautical helm by default), the name of the current cluster context, and the current namespace, all wrapped in parentheses. If you switch clusters or namespaces using the kubectl tool, the prompt updates automatically. If no cluster context is configured, the prompt shows "N/A" so you know something is missing rather than silently failing. Installation is straightforward. On a Mac you can install it through the Homebrew package manager. On Linux there is an Arch Linux package, and it is also bundled as a built-in plugin for oh-my-zsh, which is a popular framework for customizing the Zsh shell. If you prefer not to use any of those, you can clone the repository and source the script directly in your shell configuration file. Almost everything about the prompt display can be configured through environment variables you set in your shell config. You can change the colors of each element, hide the namespace, swap the separator characters, replace the default symbol with one of several alternatives, or write your own function to control how the cluster name appears. You can also turn the entire prompt off temporarily using a command called kubeoff and bring it back with kubeon, which is useful when you are working on something unrelated and want a cleaner prompt. The script works with both Bash and Zsh. It also supports OpenShift clusters, which use a different command-line tool called oc instead of kubectl. You set one variable to tell kube-ps1 which binary to use and the rest works the same way.
← jonmosco on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.