Skip to main content
Both kubectx and kubens highlight the current context or namespace in their list output. You can customize these colors or disable color output entirely.

Current Implementation (Go-based)

The Go implementation (v0.9.0+) uses a simplified color scheme with limited customization options.

Default Colors

The current context/namespace is displayed in green and bold when listing:
$ kubectx
minikube
production
staging
In the output above, the active context appears in green and bold.

Disabling Colors

To disable all color output, set the NO_COLOR environment variable:
export NO_COLOR=1
This follows the NO_COLOR standard and is respected by many command-line tools.
Color output is automatically disabled when stdout is not a terminal (e.g., when piping to another command).

Legacy Implementation (Bash-based)

The original Bash implementation offers more color customization through environment variables.
The KUBECTX_CURRENT_FGCOLOR and KUBECTX_CURRENT_BGCOLOR environment variables are deprecated in the Go implementation. They only work with the legacy Bash scripts.

Customizing Foreground and Background Colors

For the Bash implementation, you can customize both the text (foreground) and background colors using the tput command:
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6) # blue text
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7) # white background

Color Code Reference

The tput command uses the following color codes:
CodeColor
0Black
1Red
2Green
3Yellow
4Blue
5Magenta
6Cyan
7White

Examples

Blue text on white background

export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6)
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7)

Red text on black background

export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 1)
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 0)

Cyan text with default background

export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6)
# Leave BGCOLOR unset to use the default

Default Colors (Bash)

If you don’t set these variables, the Bash implementation uses:
  • Foreground: Yellow (color code 3)
  • Background: Dark/Black (color code 0)

Making Changes Permanent

To make your color preferences permanent, add the export commands to your shell configuration file:

Bash

Add to ~/.bashrc or ~/.bash_profile:
# Disable colors
export NO_COLOR=1

# Or customize colors (Bash implementation only)
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6)
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7)

Zsh

Add to ~/.zshrc:
# Disable colors
export NO_COLOR=1

# Or customize colors (Bash implementation only)
export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6)
export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7)

Fish

Add to ~/.config/fish/config.fish:
# Disable colors
set -x NO_COLOR 1

# Or customize colors (Bash implementation only)
set -x KUBECTX_CURRENT_FGCOLOR (tput setaf 6)
set -x KUBECTX_CURRENT_BGCOLOR (tput setab 7)
Remember to restart your shell or source the configuration file for changes to take effect:
source ~/.bashrc  # or ~/.zshrc

Checking Your Implementation

To determine which implementation you’re using:
kubectx --version
  • If the output shows a version number (e.g., 0.9.x), you’re using the Go implementation
  • If the output is minimal or shows bash script info, you’re using the Bash implementation
The Go implementation is recommended for new installations. You can download it from the GitHub releases page.

Build docs developers (and LLMs) love