<p>Generally in the kubernetes we can create definition files. for non-running and running pods, namespaces, deployments etc. If we generate yaml file for non running and non existing pods it create required defination file. However, if we have to get the defination file from running pod it also generates lots tags of live environment.</p>
<p>How to get only required elements while we generate yaml defination from a running pod</p>
<p>Is there any way if we can avoid getting below details after we generate pod yaml file from a running pod</p>
<p>For example if we see that after running below command it also generates lot of not required elements.</p>
<pre><code>k get po nginxs14 -n=devs14 -o yaml&gt;pod1.yaml

like:

metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {&quot;apiVersion&quot;:&quot;v1&quot;,&quot;kind&quot;:&quot;Pod&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;creationTimestamp&quot;:null,&quot;labels&quot;:{&quot;run&quot;:&quot;nginx&quot;},&quot;name&quot;:&quot;nginxs14&quot;,&quot;namespace&quot;:&quot;devs14&quot;},&quot;
  creationTimestamp: &quot;2021-04-24T11:09:56Z&quot;
  labels:
    run: nginx
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
        f:labels:
          .: {}
          f:run: {}
      f:spec:
        f:containers:
          k:{&quot;name&quot;:&quot;nginx&quot;}:
            .: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:ports:
              .: {}
              k:{&quot;containerPort&quot;:9080,&quot;protocol&quot;:&quot;TCP&quot;}:
                .: {}
                f:containerPort: {}
                f:protocol: {}
            f:readinessProbe:
              .: {}
              f:failureThreshold: {}
              f:httpGet:
                .: {}
                f:path: {}
                f:port: {}
                f:scheme: {}
              f:periodSeconds: {}
              f:successThreshold: {}
              f:timeoutSeconds: {}
            f:resources: {}
            f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:terminationGracePeriodSeconds: {}
    manager: kubectl-client-side-apply
    operation: Update
    time: &quot;2021-04-24T11:09:56Z&quot;
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          k:{&quot;type&quot;:&quot;ContainersReady&quot;}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{&quot;type&quot;:&quot;Initialized&quot;}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{&quot;type&quot;:&quot;Ready&quot;}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
        f:containerStatuses: {}
        f:hostIP: {}
        f:phase: {}
        f:podIP: {}
        f:podIPs:
          .: {}
</code></pre>

<blockquote>
<p>after running below command it also generates lot of not required elements</p>
</blockquote>
<p>A large part of the problem you describe is the <code>managedFields:</code>. I agree this is very verbose and mostly annoying output.</p>
<p>However, this is now fixed. If you upgrade to <code>kubectl</code> version 1.21+ this is <a href="https://github.com/kubernetes/kubernetes/issues/90066#issuecomment-814063884" rel="nofollow noreferrer">not shown as default</a>. Now you need to add <code>--show-managed-fields</code> to show these fields.</p>
