Skip to content

Instantly share code, notes, and snippets.

@yonixw
Last active March 2, 2022 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonixw/2e247e794a0c71a52a1d7d038766442c to your computer and use it in GitHub Desktop.
Save yonixw/2e247e794a0c71a52a1d7d038766442c to your computer and use it in GitHub Desktop.
Export kubectl readable yamls
export ns=NAMESPACE # Change this
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
for n in $(kubectl -n $ns get -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob)
do
echo "Exporting $n..."
mkdir -p $(dirname $n)
# old # kubectl get -o=yaml --export $n > $n.yaml
kubectl -n $ns get $n -o yaml | kubectl-neat > $n.yaml
done

Install - No Admin

from: https://krew.sigs.k8s.io/docs/user-guide/setup/install/

Krew (plugin manager)

(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
)

Neat (kubectl plugin)

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
kubectl-krew update
kubectl-krew install neat

Links

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