Print the active Kubernetes context, cluster, user, and namespace
Build a paste-ready command, then review its compatibility and effects before running it.
kubectl config view --minify -o json | jq -r '.contexts[0].name as $c | .contexts[0].context | "context=\($c) cluster=\(.cluster) user=\(.user) namespace=\(.namespace // "default")"'read-onlyno known side effects Compatibility
Linux + macOS + WindowsVerified for Linux, macOS, Windows using bash, zsh, powershell syntax.
Operational knowledgereview due 2027-01-19
Requirementskubectlkubectl must be installed and available on PATH.
Version supportkubectl Current supported releasesVerified for linux, macos, windows using bash, zsh, powershell syntax; consult compatibility notes for platform-specific differences.
Expected signalscontext=production-eu cluster=prod-eu user=sre@example.com namespace=paymentsRepresentative successful output; values vary with the selected target and system state.
Known errorskubectl: command not foundkubectl is missing or is not available on PATH.
Verifykubectl config view --minify -o json | jq -r '.contexts[0].name as $c | .contexts[0].context | "context=\($c) cluster=\(.cluster) user=\(.user) namespace=\(.namespace // "default")"'The output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01kubectlCommandRuns the kubectl stage of this one-liner.
02configArgumentPasses config to kubectl.
03viewArgumentPasses view to kubectl.
04--minifyOptionConfigures kubectl with the --minify option.
05-oOptionSelects an output file or output format for this command.
06jsonArgumentPasses json to kubectl.
07|PipelinePasses the output on the left to the command on the right.
08jqCommandRuns the jq stage of this one-liner.
09-rOptionEnables raw, recursive, or reverse mode for this command.
10'.contexts[0].name as $c | .contexts[0].context | "context=\($c) cluster=\(.cluster) user=\(.user) namespace=\(.namespace // "default")"'ArgumentPasses '.contexts[0].name as $c | .contexts[0].context | "context=\($c) cluster=\(.cluster) user=\(.user) namespace=\(.namespace // "default")"' to jq.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
kubectl config view --minify -o json | jq -r '.contexts[0].name as $c | .contexts[0].context | "context=\($c) cluster=\(.cluster) user=\(.user) namespace=\(.namespace // "default")"'
Example output
context=production-eu cluster=prod-eu user=sre@example.com namespace=payments
Illustrative output — exact values vary by system and data.
Official sources