1

I'm trying to export a daemonset from my kubernetes cluster but I dont want any of the metadata. Is there a way I can export the manifest file without the metadata, like creationtimestamp, uid_selflink, etc.

for example, something like this would be perfect:

kubectl get daemonset mydaemonset --no-meta-data -o yaml > exported-mydaemonset.yaml

I want to discard information about the current object state.

Chesneycar
  • 545
  • 16
  • 43

2 Answers2

2

You can make use of the annotation field kubectl.kubernetes.io/last-applied-configuration, which holds the resource initial applied configuration without auto-generated fields.

Get it manually, or parse it with yq:

kubectl get daemonset mydaemonset -o yaml | \
yq r - 'metadata.annotations."kubectl.kubernetes.io/last-applied-configuration"'
Eduardo Baitello
  • 10,469
  • 7
  • 46
  • 74
  • Hi Eduardo, your suggestion helped me in my research on how to remove this metadata. I eventually used a combination of your script and jsonpath to remove the unwanted metadata. – Chesneycar Oct 31 '20 at 06:49
0

You could also do kubectl apply view-last-applied daemonset mydaemonset -o yaml which gives you the output in the format you require.