<p>I am trying to create a pod with dru-run and check it in yaml as follows:</p>
<pre><code>k run --restart=Never --image=busybox busybox --dry-run=server -o yaml -- env &gt; mypod.yaml
</code></pre>
<p>The produced <code>yaml</code> file has a ton of fields unknown to me such as:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: &quot;2020-11-23T15:33:39Z&quot;
  labels:
    run: busybox
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:labels:
          .: {}
          f:run: {}
      f:spec:
        f:containers:
          k:{&quot;name&quot;:&quot;busybox&quot;}:
            .: {}
            f:args: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:resources: {}
            f:terminationMessagePath: {}
            f:terminationMessagePolicy: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:terminationGracePeriodSeconds: {}
    manager: kubectl-run
    operation: Update
    time: &quot;2020-11-23T15:33:39Z&quot;
  name: busybox
  namespace: mynamespace
  selfLink: /api/v1/namespaces/mynamespace/pods/busybox
  uid: 79e514a9-3c55-4d62-8068-9244252efaa3
spec:
  containers:
  - args:
    - env
    image: busybox
    imagePullPolicy: Always
    name: busybox
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-h57fg
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-h57fg
    secret:
      defaultMode: 420
      secretName: default-token-h57fg
status:
  phase: Pending
  qosClass: BestEffort
</code></pre>
<p>Is there a way to avoid these fields being printed out? (and what is their purpose)</p>
<p>working with</p>
<pre><code>k version
Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;19&quot;, GitVersion:&quot;v1.19.0&quot;, GitCommit:&quot;e19964183377d0ec2052d1f1fa930c4d7575bd50&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-08-26T14:30:33Z&quot;, GoVersion:&quot;go1.15&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;19&quot;, GitVersion:&quot;v1.19.0&quot;, GitCommit:&quot;e19964183377d0ec2052d1f1fa930c4d7575bd50&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-08-26T14:23:04Z&quot;, GoVersion:&quot;go1.15&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

<p><strong>Update</strong><br />
In Kubernetes 1.21 <code>managedFields</code> has been removed from default <code>kubectl</code> output.
<a href="https://github.com/kubernetes/kubernetes/pull/96878" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/pull/96878</a><br />
Use <code>kubectl --show-managed-fields</code> to display it.</p>
<hr />
<p>That's a new feature called Server-side Apply, enabled by default since Kubernetes 1.18.<br />
It is intended to improve object merge algorithms by tracking fields ownership.</p>
<blockquote>
<p>Server-side Apply works by keeping track of which actor of the system
has changed each field of an object. It does so by diffing all updates
to objects, and recording all the fields that have changed as well the
time of the operation. All this information is stored in the
managedFields in the metadata of objects. Since objects can have many
fields, this field can be quite large.</p>
<p>When someone applies, we can then use the information stored within
managedFields to report relevant conflicts and help the merge
algorithm to do the right thing.
<a href="https://kubernetes.io/blog/2020/04/01/kubernetes-1.18-feature-server-side-apply-beta-2/" rel="nofollow noreferrer">https://kubernetes.io/blog/2020/04/01/kubernetes-1.18-feature-server-side-apply-beta-2/</a></p>
</blockquote>
<p>A lot of ppl are complaining about noisy output.<br />
Here is the main discussion.<br />
<a href="https://github.com/kubernetes/kubernetes/issues/90066" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/90066</a></p>
<p>For now there is no any suitable way to remove extra fields from the output.</p>
<ol>
<li><p>You could disable the whole feature.  <a href="https://github.com/kubernetes/kubernetes/issues/90066#issuecomment-639512202" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/90066#issuecomment-639512202</a><br />
But that's not recommended, as it was established for a reason, and new tools and components are likely to rely on a certain behavior it enables.</p>
</li>
<li><p>You could use <code>jq</code> or <code>yq</code> in conjunction with scripts, aliases etc.<br />
<a href="https://github.com/kubernetes/kubernetes/issues/89080#issuecomment-626127959" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/89080#issuecomment-626127959</a></p>
</li>
</ol>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>kyaml() {
  kubectl -o yaml "$@" \
    | yq d - 'items[*].metadata.managedFields' \
    | yq d - '.metadata.managedFields' \
    | yq d - 'items[*].metadata.ownerReferences' \
    | yq d - 'metadata.ownerReferences' \
    | yq d - 'items[*].status' \
    | yq d - 'status'
}
kyaml get pods</code></pre>
</div>
</div>
</p>
