Juggle your Kubernetes Installations with Ease

In most projects with Kubernetes systems, we see a lot of different custom setups how people deal with multiple Kubernetes environments.

The most convenient way I encountered so far is direnv.

🥇 direnv - unclutter your .profile

TL&DR

Install direnv - tune your .zshrc like this:

eval "$(direnv hook zsh)"
eval "$(starship init zsh)"

Then activate on a per-directory basis via .envrc:

$ cd environment/dev
direnv: error … .envrc is blocked. Run `direnv allow` to approve its content

$ direnv allow
…
direnv: export +KUBECONFIG

Sample Setup Session for OSX

The following is more or less the log of an installation session for a developer working with several Kubernetes environments/projects. We assume Homebrew to already present on the system.

Depending on your distribution, please follow the installation documentation.

$ brew install direnv 
…
==> Pouring direnv--2.31.0.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/direnv/2.31.0: 11 files, 9MB

(bonus) Starship - cross-shell prompt

starship - The minimal, blazing-fast, and infinitely customizable prompt for any shell!

In combination with direnv, you’ll never get lost in your Kubernetes universe again :-)

$ brew install starship
…
🍺  /usr/local/Cellar/starship/1.6.3: 11 files, 6.2MB

Tune the configuration in .config/starship.toml

[kubernetes]
format = 'on [⛵ ($user on )($cluster in )$context \($namespace\)](green) '
disabled = false

…and you’ll always know your current Kubernetes context.

(bonus) Nerd Fonts

brew tap homebrew/cask-fonts 
brew install font-fira-code
brew install font-Fira-Code-nerd-font
brew install font-hack-nerd-font

Then configure the font-family Hack Nerd Font in your favorite terminals and tools…

Kudos to Quack~ for Mac install Nerd Font (Fire code)

🚀 Happy K8s hacking!


🙌 Photo by Conor Samuel on Unsplash