Skip to content

Instantly share code, notes, and snippets.

@shivanshs9
Last active July 16, 2026 07:14
Show Gist options
  • Select an option

  • Save shivanshs9/fc49b5e73861a6482bd6c347b4fdfd5b to your computer and use it in GitHub Desktop.

Select an option

Save shivanshs9/fc49b5e73861a6482bd6c347b4fdfd5b to your computer and use it in GitHub Desktop.
Search all k8s secrets in a given namespace (both key/value)
function k8s_search_secret
if test (count $argv) -lt 2
echo "Usage: k8s_search_secret <namespace> <search_term>"
return 1
end
set NAMESPACE $argv[1]
set SEARCH_TERM $argv[2]
# Get all secrets in the namespace and decode them
kubectl get secrets -n $NAMESPACE -o json | jq -r --arg search "$SEARCH_TERM" '
[.items[]
| {name: .metadata.name, data: .data}
| select(.data != null)
| .name as $secret_name
| .data
| to_entries[]
| {
secret: $secret_name,
key: .key,
value: (try (.value | @base64d) catch "INVALID_UTF8")
}
| select((.key | test($search; "i")) or (.value | test($search; "i")))
]
| (["secret","key","value"]),
(.[] | [.secret, .key, .value])
| @csv
'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment