utility-option

kubectl dry-run

Provider-specific preview. Client mode does not persist requested object; server mode sends a non-persisting request subject to authorization and admission. Client mode is not guaranteed network-free. Example is mock-only.

Formal Syntax & Structure

bash syntaxbash
kubectl create namespace NAME --dry-run=client -o=json

Return Value

exit status

Provider-specific preview. Client mode does not persist requested object; server mode sends a non-persisting request subject to authorization and admission. Client mode is not guaranteed network-free. Example is mock-only.

Working Example

Example Snippetbash
mkdir mockcat > mock/kubectl <<'MOCK'#!/bin/bash[[ $# == 5 && $1 == create && $2 == namespace && $3 == demo && $4 == --dry-run=client && $5 == -o=json ]] || exit 2printf '{"kind":"Namespace","metadata":{"name":"demo"}}\n'MOCKchmod 700 mock/kubectl./mock/kubectl create namespace demo --dry-run=client -o=json > preview.json || exit 1jq -r '.metadata.name' preview.json
Bash Reference