This plugin allows for easy secret decoding. Useful if you want to see what's inside of a secret without always go through the following:
kubectl get secret <secret> -o yaml- Copy base64 encoded secret
echo "b64string" | base64 -d
Instead you can now do:
# print secret keys
kubectl view-secret <secret>
# decode specific entry
kubectl view-secret <secret> <key>
# decode all contents
kubectl view-secret <secret> -a/--all
# print keys for secret in different namespace
kubectl view-secret <secret> -n/--namespace <ns>
# print keys for secret in different context
kubectl view-secret <secret> -c/--context <ctx>
# print keys for secret by providing kubeconfig
kubectl view-secret <secret> -k/--kubeconfig <cfg>
# suppress info output
kubectl view-secret <secret> -q/--quiet
# output in JSON format
kubectl view-secret <secret> -o json
# output in YAML format
kubectl view-secret <secret> -o yaml
This plugin supports bash completion for kubectl versions 1.26 and later. To enable completion:
Follow the Kubernetes docs to install shell completion.
# Place the following completion script somewhere in your $PATH, e.g. /usr/local/bin in this context
cat << "EOF" | sudo tee /usr/local/bin/kubectl_complete-view_secret > /dev/null
#!/bin/bash
kubectl view-secret __complete "$@"
EOF
# Make it executable
sudo chmod +x /usr/local/bin/kubectl_complete-view_secretThen restart your shell or run:
source ~/.bashrc# Check bash-completion is loaded
type _get_comp_words_by_ref
# Check kubectl completion is loaded
type _kubectl
# Test completion
kubectl view-secret <TAB>Now you can use Tab completion for:
- Secret names:
kubectl view-secret <TAB> - Secret keys:
kubectl view-secret <secret> <TAB> - Namespaces:
kubectl view-secret <secret> -n <TAB>
- Text: Default human-readable format
- JSON: Structured output for automation and scripting
- YAML: Alternative structured format
Supports decoding various Kubernetes secret types:
- Opaque: Standard base64 encoded secrets
- Helm: Double base64 encoded + gzip compressed Helm release data
- TLS: PEM encoded certificates and private keys
- Docker Config: JSON configuration for Docker registries
- SSH Auth: SSH private keys
- Basic Auth: Username/password credentials
- Service Account Tokens: JWT tokens
- Secret Selection: When no secret is specified, provides an interactive list to choose from
- Key Selection: When multiple keys exist, allows selecting specific keys or viewing all
This plugin is available through krew via:
kubectl krew install view-secretYou can find the latest binaries in the releases section.
To install it, place it somewhere in your $PATH for kubectl to pick it up.
Note: If you build from source or download the binary, you'll have to change the name of the binary to kubectl-view_secret (- to _ in view-secret)
due to the enforced naming convention for plugins by kubectl. More on this here.
Thanks to external contributions the plugin is available in the Arch user repository.
| Package | Contributor |
|---|---|
| bin | @jocelynthode |
| git | @aryklein |
You can install the latest version from Nixpkgs (25.05, unstable) or try it via a temporary nix-shell:
nix-shell -p kubectl-view-secret
# Clone this repository (or your fork)
git clone https://github.com/elsesiy/kubectl-view-secret
cd kubectl-view-secret
make
This repository is available under the MIT license.
