How do I export a kubernetes manifest file without the metadata?

10/30/2020

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
amazon-eks
amazon-web-services
bash
devops
kubernetes

2 Answers

2/16/2021

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

-- shadowthrone
Source: StackOverflow

10/30/2020

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
Source: StackOverflow