-
Notifications
You must be signed in to change notification settings - Fork 87
PluginKubernetes
Display current Kubernetes context and namespace with production warnings and interactive selectors.
dev/default # Development context - green/ok
staging/app-ns # Staging context - green/ok
prod/web-app # Production context - red/error
(disconnected) # Cluster unreachable - yellow/warning
| Property | Value |
|---|---|
| Platform | macOS, Linux |
| Dependencies |
kubectl (optional - reads kubeconfig directly), fzf (optional - for selectors) |
| Content Type | dynamic |
| Presence | conditional |
# kubectl (Kubernetes CLI)
# macOS
brew install kubectl
# Linux (Debian/Ubuntu)
sudo apt install kubectl
# Linux (Fedora)
sudo dnf install kubectl
# fzf (for interactive selectors)
# macOS
brew install fzf
# Linux
sudo apt install fzf# Enable plugin
set -g @powerkit_plugins "kubernetes"# Enable plugin
set -g @powerkit_plugins "kubernetes"
# Display options
set -g @powerkit_plugin_kubernetes_display_mode "connected"
set -g @powerkit_plugin_kubernetes_show_context "true"
set -g @powerkit_plugin_kubernetes_show_namespace "true"
set -g @powerkit_plugin_kubernetes_separator "/"
# Connectivity options
set -g @powerkit_plugin_kubernetes_connectivity_timeout "2"
set -g @powerkit_plugin_kubernetes_connectivity_cache_ttl "120"
# Production warning
set -g @powerkit_plugin_kubernetes_warn_on_prod "true"
set -g @powerkit_plugin_kubernetes_prod_keywords "prod,production,prd"
# Icon
set -g @powerkit_plugin_kubernetes_icon ""
# Interactive selectors (requires fzf)
set -g @powerkit_plugin_kubernetes_keybinding_context "C-k C-c"
set -g @powerkit_plugin_kubernetes_keybinding_namespace "C-k C-n"
set -g @powerkit_plugin_kubernetes_popup_width "50%"
set -g @powerkit_plugin_kubernetes_popup_height "50%"
# Cache duration (seconds)
set -g @powerkit_plugin_kubernetes_cache_ttl "30"| Option | Type | Default | Description |
|---|---|---|---|
@powerkit_plugin_kubernetes_display_mode |
string | connected |
connected (only when reachable) or always
|
@powerkit_plugin_kubernetes_show_context |
bool | true |
Show context name |
@powerkit_plugin_kubernetes_show_namespace |
bool | true |
Show namespace |
@powerkit_plugin_kubernetes_separator |
string | / |
Separator between context and namespace |
@powerkit_plugin_kubernetes_connectivity_timeout |
number | 2 |
Cluster connectivity timeout (seconds) |
@powerkit_plugin_kubernetes_connectivity_cache_ttl |
number | 120 |
Connectivity check cache (seconds) |
@powerkit_plugin_kubernetes_warn_on_prod |
bool | true |
Show warning health for production contexts |
@powerkit_plugin_kubernetes_prod_keywords |
string | prod,production,prd |
Comma-separated production keywords |
@powerkit_plugin_kubernetes_icon |
icon | |
Kubernetes icon |
@powerkit_plugin_kubernetes_keybinding_context |
string | `` | Keybinding for context selector (e.g., C-k C-c) |
@powerkit_plugin_kubernetes_keybinding_namespace |
string | `` | Keybinding for namespace selector (e.g., C-k C-n) |
@powerkit_plugin_kubernetes_popup_width |
string | 50% |
Popup width for selectors |
@powerkit_plugin_kubernetes_popup_height |
string | 50% |
Popup height for selectors |
@powerkit_plugin_kubernetes_cache_ttl |
number | 30 |
Cache duration in seconds |
@powerkit_plugin_kubernetes_show_only_on_threshold |
bool | false |
Not applicable for this plugin |
| State | Condition | Visibility |
|---|---|---|
active |
Context exists and connected (or display_mode=always) | Visible |
inactive |
No kubeconfig or context | Hidden |
degraded |
Context exists but cluster unreachable (display_mode=connected) | Visible with warning |
| Level | Condition | Color |
|---|---|---|
ok |
Context available and connected | Green |
warning |
Cluster unreachable | Yellow |
error |
Production context (when warn_on_prod=true) | Red |
| Context | Description |
|---|---|
no_context |
No kubeconfig or context set |
disconnected |
Cluster not reachable |
production |
Production context (matches prod_keywords) |
staging |
Staging context |
development |
Development context |
local |
Local cluster (minikube, kind, k3s, docker-desktop) |
connected |
Connected but environment type unknown |
Only shows when cluster is reachable:
set -g @powerkit_plugin_kubernetes_display_mode "connected"- Checks cluster connectivity (cached for 120s)
- Hides when cluster is down
- Useful for on-demand clusters
Always shows context, even when cluster is unreachable:
set -g @powerkit_plugin_kubernetes_display_mode "always"- Shows even when cluster is down
- No connectivity checks
- Faster, less accurate
set -g @powerkit_plugin_kubernetes_show_context "true"
set -g @powerkit_plugin_kubernetes_show_namespace "true"Output: prod/web-app
set -g @powerkit_plugin_kubernetes_show_context "true"
set -g @powerkit_plugin_kubernetes_show_namespace "false"Output: prod
set -g @powerkit_plugin_kubernetes_show_context "false"
set -g @powerkit_plugin_kubernetes_show_namespace "true"Output: web-app
set -g @powerkit_plugin_kubernetes_separator " | "Output: prod | web-app
The plugin automatically shortens context names:
| Original | Shortened | Reason |
|---|---|---|
user@cluster |
cluster |
Removes user prefix |
cluster:context |
context |
Removes cluster prefix |
arn:aws:eks:region:account:cluster/name |
name |
AWS EKS shortening |
gke_project_region_cluster |
cluster |
GKE shortening |
When warn_on_prod is enabled, contexts matching production keywords show in red:
Default keywords: prod, production, prd
Example matches:
-
prod-cluster✓ -
production-east✓ -
prd-db✓ -
staging-prod✓ (contains "prod") -
dev-cluster✗
Keybindings require fzf or gum and kubectl.
Interactive context and namespace selector.
| Action | Description |
|---|---|
context |
Select Kubernetes context (default) |
namespace |
Select namespace in current context |
# Switch context
./src/helpers/kubernetes_selector.sh context
# Switch namespace
./src/helpers/kubernetes_selector.sh namespaceset -g @powerkit_plugin_kubernetes_keybinding_context "C-k C-c"- Lists all available contexts
- Switches to selected context
- Works even when cluster is unreachable
- Clears cache after switch
set -g @powerkit_plugin_kubernetes_keybinding_namespace "C-k C-n"- Lists namespaces from current cluster
- Requires cluster connectivity
- Updates current context namespace
- Clears cache after switch
set -g @powerkit_plugins "kubernetes"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_display_mode "connected"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_display_mode "always"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_show_namespace "false"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_prod_keywords "prod,production,live,prd"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_warn_on_prod "false"set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_keybinding_context "C-k c"
set -g @powerkit_plugin_kubernetes_keybinding_namespace "C-k n"Usage:
- Press
Ctrl+kthencto switch context - Press
Ctrl+kthennto switch namespace
The plugin reads kubeconfig in this order:
-
$KUBECONFIGenvironment variable -
~/.kube/config(default)
# In your shell config (~/.bashrc, ~/.zshrc)
export KUBECONFIG=~/.kube/config:~/.kube/prod-config:~/.kube/dev-config-
Check if kubeconfig exists:
ls -la ~/.kube/config echo $KUBECONFIG
-
Verify current context:
kubectl config current-context kubectl config view --minify
-
List all contexts:
kubectl config get-contexts
If display_mode=connected and always shows disconnected:
-
Test cluster connectivity:
kubectl cluster-info kubectl get nodes
-
Check connectivity timeout:
# Increase timeout for slow networks set -g @powerkit_plugin_kubernetes_connectivity_timeout "5"
-
Switch to always mode:
set -g @powerkit_plugin_kubernetes_display_mode "always"
-
Verify kubectl shows correct info:
kubectl config current-context kubectl config view --minify | grep namespace -
Clear cache:
rm ~/.cache/tmux-powerkit/kubernetes* tmux refresh-client -S
-
Check if fzf is installed:
which fzf
-
Test selector manually:
# Context selector kubectl config get-contexts -o name | fzf # Namespace selector kubectl get namespaces -o name | sed 's/namespace\///' | fzf
-
Verify keybinding syntax:
# Valid formats "C-k c" # Ctrl+k then c "C-k C-c" # Ctrl+k then Ctrl+c "M-k" # Alt+k
If connectivity checks are slow:
-
Increase cache TTL:
set -g @powerkit_plugin_kubernetes_connectivity_cache_ttl "300"
-
Use always mode:
set -g @powerkit_plugin_kubernetes_display_mode "always"
The plugin can work without kubectl:
- Reads
~/.kube/configdirectly usingawk - Parses current context and namespace
- Falls back to kubectl if available
This makes the plugin lightweight and fast.
- Connected mode: Checks connectivity every 120s (cached)
- Always mode: No connectivity checks (faster)
- Context/namespace read from file (very fast)
- kubectl only used for connectivity check
- Cache invalidated when kubeconfig changes (auto-detected)
Track which cluster you're working on:
set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_show_context "true"Visual warning when in production:
set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_warn_on_prod "true"
# Production contexts show in redInteractive selectors for fast switching:
set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_keybinding_context "C-k c"
set -g @powerkit_plugin_kubernetes_keybinding_namespace "C-k n"Show only when working with kubernetes:
set -g @powerkit_plugins "kubernetes"
set -g @powerkit_plugin_kubernetes_display_mode "connected"The plugin detects environment type from context name:
| Pattern | Context Type |
|---|---|
*prod*, *production*, *prd*
|
Production |
*stag*, *staging*
|
Staging |
*dev*, *development*
|
Development |
*local*, *minikube*, *docker-desktop*, *kind*, *k3*
|
Local |
This affects health level when warn_on_prod=true.
- PluginTerraform - Terraform workspace
- PluginCloud - Cloud provider context
- PluginGit - Git branch indicator
- PluginSsh - SSH session indicator