<p>How to copy/ backup an existing kubernetes resource and its related entities as well as a backup option </p>

<p>for example when I run <code>kubectl get deploy my-deployment  -n staging  &gt; backupdeploy.yaml</code></p>

<p>I get a file named backupdeploy.yaml with all the annotations and creation timestamps. </p>

<p>I need to be able to achieve a copy of the original my-deployment.yaml and the related resources in separate yamls.
is there any shell script available to do this?</p>

<p>I also need the secrets, configmaps, svc, pvc that are tied to the " <strong>my-deployment</strong> "</p>

<p>Please help me out. Thanks.</p>

<p>In order to achieve that you need to use the <code>--export</code> export flag:</p>

<blockquote>
  <p>If true, use 'export' for the resources. Exported resources are
  stripped of cluster-specific information.</p>
</blockquote>

<p>So it would look like something like this: <code>kubectl get deploy my-deployment -n staging --export</code></p>

<p>Please let me know if that helped. </p>
