explaingit

jonmosco/kube-ps1

3,783ShellAudience · ops devopsComplexity · 1/5Setup · easy

TLDR

A shell script that adds your current Kubernetes cluster and namespace to your terminal prompt, so you always know which environment you're working in before running any command.

Mindmap

mindmap
  root((kube-ps1))
    What it shows
      Current cluster
      Current namespace
      Helm symbol
    Shell Support
      Bash
      Zsh
    Install Methods
      Homebrew
      oh-my-zsh plugin
      Manual source
    Customization
      Colors
      Symbol choice
      Hide namespace
      kubeon kubeoff
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Display your active Kubernetes cluster and namespace in the terminal prompt so you never accidentally run commands in the wrong environment.

USE CASE 2

Temporarily hide the Kubernetes prompt with kubeoff when working on unrelated tasks, and bring it back with kubeon.

USE CASE 3

Customize prompt colors, symbols, and separator characters to match your team's shell configuration style.

USE CASE 4

Use kube-ps1 with OpenShift clusters by setting one variable to point to the oc CLI instead of kubectl.

Tech stack

Shell

Getting it running

Difficulty · easy Time to first run · 5min

Install via Homebrew on Mac or source the script in your shell config file, no additional infrastructure required.

License terms are not described in the explanation.

In plain English

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.

Copy-paste prompts

Prompt 1
Install kube-ps1 on my Mac using Homebrew and configure it in my .zshrc so it shows my cluster and namespace in the prompt.
Prompt 2
Show me how to source kube-ps1 manually on Linux without oh-my-zsh and add it to my Bash prompt.
Prompt 3
Customize kube-ps1 to show the cluster name in blue and the namespace in yellow using environment variables in my shell config.
Prompt 4
Configure kube-ps1 to work with OpenShift so it uses the oc command instead of kubectl.
Open on GitHub → Explain another repo

← jonmosco on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.