Can we extract existing deployment yaml without the metadata junk? kubectl get . . .

Mayur Sharma:
Can we extract existing deployment yaml without the metadata junk?

kubectl get deployment -o yaml gives all the junk with actual meaningful data

Tej_Singh_Rana:
Hello, @Mayur Sharma
You can try with grep command. Like this way to extract fields kubectl get po nginx -oyaml | grep -v 'f:' > nginx.yaml

Fernando Jimenez:
@Mayur Sharma That metadata is part of the server-side apply. Natively, there is nothing to prevent from showing up unless you are in version 1.21. As an alternative you may use an external command filter like grep -v However, that leaves still quite a bit of residue behind. I have been experimenting with sed, instead, as the filter and it shows some promise.

kubectl -n kube-system get deploy coredns -o yaml | sed '/  managedFields:/,/  name:/{/  name:/b;d;}' > coredns.yaml

Mayur Sharma:
Thanks @Tej_Singh_Rana and @Fernando Jimenez, I will try it out.

Shwetha Shenoy V:
kubernetes 1.21 introduced a flag --show-managed-fields for this. By default, no managed fields are output in the yaml. To get them, you have to explicitly set the flag to true.