Skip to content

Instantly share code, notes, and snippets.

@clux
Last active October 14, 2022 17:26
Show Gist options
  • Save clux/06c4277e2b3b71c6369f749ae76e4e46 to your computer and use it in GitHub Desktop.
Save clux/06c4277e2b3b71c6369f749ae76e4e46 to your computer and use it in GitHub Desktop.
kubectl get yaml without managedFields
# kubectl < 1.21
ky() {
local -r resource="${1:-$(kubectl api-resources --no-headers | choose 0 | fzf)}"
local -r name="${2:-$(kubectl get ${resource} --no-headers | choose 0 | fzf)}"
kubectl get "${resource}" "${name}" -oyaml \
| yq 'del(.metadata.managedFields)' -y \
| bat -l=yaml --plain --theme=DarkNeon
}
# kubectl >= 1.21
ky() {
local -r resource="${1:-$(kubectl api-resources --no-headers | choose 0 | fzf)}"
local -r name="${2:-$(kubectl get ${resource} --no-headers | choose 0 | fzf)}"
kubectl get "${resource}" "${name}" -oyaml | bat -l=yaml --plain --theme=DarkNeon
}
@clux
Copy link
Author

clux commented Oct 13, 2021

uses:

then put some aliases elsewhere:

alias kyp="ky pod"
alias kyc="ky cm"
alias kysec="ky secret"
alias kyd="ky deploy"
alias kyrs="ky rs"
alias kyj="ky job"
alias kycj="ky cj"
alias kysm="ky sm"
alias kys="ky service"
alias kysa="ky sa"
alias kyn="ky node"
alias kyh="ky hpa"
alias kyf="ky foo"

to avoid the double fzf prompt if you know what resource you want.
NB: you don't actually need to strip yourself if you have kubectl >= 1.21 due to kubernetes/kubernetes#96878

asciicast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment