Kubesafe 🔁 Tired of accidentally running dangerous commands on the wrong Kubernetes cluster? Meet kubesafe — your safety net for cluster management.
<a href="https://github.com/Telemaco019/kubesafe/actions"><img src="https://github.com/Telemaco019/kubesafe/actions/workflows/ci.yaml/badge.svg" alt="Build Status"></a>

kubesafe allows you to safely run commands acrosss multiple Kubernetes contexts. By allowing you to mark specific contexts as "safe" and define a list of protected commands, kubesafe makes sure you never accidentally run a dangerous command on the wrong cluster.
Key Features:
Simply prepend kubesafe to any command you want to run:
# Example with kubectl
kubesafe kubectl delete pod my-pod
# Example with Helm
kubesafe helm upgrade my-release stable/my-chart
Kubesafe seamlessly wraps any CLI command you provide as the first argument (e.g., kubectl, helm, kubecolor, etc.). If you attempt to run a protected command in a safe context, kubesafe will prompt you for confirmation before proceeding.
For convenience, you can set aliases in your shell configuration:
alias kubectl='kubesafe kubectl'
alias helm='kubesafe helm'
Now, every time you use kubectl or helm, kubesafe will automatically protect your commands!
To manage your safe contexts and protected commands, see the Managing contexts section.
$ brew tap Telemaco019/kubesafe
$ brew install kubesafe
$ go install github.com/telemaco019/kubesafe/kubesafe@latest
For shell completion setup, see Shell completion.
Kubesafe makes it easy to manage your safe contexts and protected commands. To see all available options, run:
kubesafe --help
To add a safe context, simply execute:
kubesafe context add
Kubesafe will guide you interactively to select a context to mark as "safe" and choose the commands you want to protect. Alternatively, you can add a safe context directly by specifying its name:
kubesafe context add my-context
The provided value can also be a regular expression to match multiple contexts:
kubesafe context add "prod-.*"
This will mark all context starting with prod- as safe.
By default, kubesafe allows you to interactively choose commands to protect from a predefined list. However, if you prefer to specify your own custom commands, you can provide them as a comma-separated list like this:
kubesafe context add my-context --commands "delete,apply,upgdrade"
To display all your configured safe contexts and their protected commands, use:
kubesafe context list
To remove a context from your list of safe contexts, run:
kubesafe context remove my-context
To view usage statistics for your safe contexts, including how many times protected commands were blocked, use:
kubesafe stats
Kubesafe supports a non-interactive mode, which can be enabled by adding the --no-interactive flag directly after the kubesafe command.
In this mode, kubesafe will skip confirmation prompts and automatically abort the command if it is protected.
Example:
kubesafe --no-interactive kubectl delete pod my-pod
You can hook up kubesafe with the Kubernetes VSCode Extension
to add an extra safety layer to your workflow. Once set up, you'll get a warning popup whenever you try to run a protected command in a safe context.
Just make sure kubesafe is running in non-interactive mode (--no-interactive) and tell the extension to
use kubesafe as your kubectl command.
kubesafe with the --no-interactive flag.Create a file named kubesafe-kubectl and give it execution permissions:
```shell cat <<'EOT' > kubesafe-kubectl #!/bin/sh kubesafe --no-interactive kubectl "$@" EOT
chmod +x kubesafe-kubectl ```
Set the path to the kubesafe-kubectl script in the Kubernetes extension settings:
Open the VSCode settings (Cmd + , on Mac, Ctrl + , on Windows/Linux)
Kubernetes: Kubectl PathVscode-kubernetes: Kubectl-path to the path of the kubesafe-kubectl script.Screenshot

Example

Kubesafe supports shell completion for Bash, Zsh, and Fish. The completion scripts automatically delegate to the wrapped command's completion system when completing subcommands (e.g., kubesafe kubectl get <TAB> uses kubectl's completions).
# Load completions for commands you want to wrap (required for delegation)
source <(kubectl completion bash)
source <(helm completion bash) # Add other commands as needed
# Load kubesafe completion
source <(kubesafe completion bash)
To load completions for each session, add the above lines to your ~/.bashrc.
# Load completions for commands you want to wrap (required for delegation)
source <(kubectl completion zsh)
source <(helm completion zsh) # Add other commands as needed
# Load kubesafe completion
source <(kubesafe completion zsh)
To load completions for each session, add the above lines to your ~/.zshrc.
# Load completions for commands you want to wrap (required for delegation)
kubectl completion fish | source
helm completion fish | source # Add other commands as needed
# Load kubesafe completion
kubesafe completion fish | source
To load completions for each session, run:
kubesafe completion fish > ~/.config/fish/completions/kubesafe.fish
Kubesafe draws inspiration from existing kubectl plugins that offer similar features but are restricted to working exclusively with kubectl:
This project is licensed under the Apache License. See the LICENSE file for details.
$ claude mcp add kubesafe \
-- python -m otcore.mcp_server <graph>