CKA course: -o yaml outputs unwanted fields but in solution video the output doesn't contain these fields

I’ve been following the CKA course on KodeKloud.

I require some clarification on a specific kubectl command -

kubectl get <pod-name> -o yaml

For scenarios where you’d need to make minor edits to a PodSpec using this would output the YAML required to spin up a similar pod after making your edits.

The output contains unwanted fields that are updated by Kubernetes to the running pod (ex. managedFields, status) which I delete and proceed with pod creation.

However, I’ve noticed that in the solution videos whenever “-o yaml” is used the output only contains the necessary fields.

I just want to confirm if the video is edited for brevity or if there is any work-around to get the YAML without the unwanted fields?

I’ve tried the Kubernetes docs but they only mention “-o yaml” outputs the spec in YAML format.

Thanks in advance.

Hello, @vijaypsamy
Yes, you are correct. Because unwanted fields keeping in the video’s example is not make sense.

Thanks for the quick response! I thought so too.

We won’t work on that managed fields. So removed from the video and only necessary fields mentioned in the video. For better understanding.

Hello @player001,

I think your answer is not completely accurate. Please, correct me if I am wrong with the following:

The following image shows the output using $ kubectl get po nginx-pod -o yaml for a simple pod created on a kubernetes version 1.13 (and i think the output is similar until version 1.17):


That output is similar of the ones that we see in the videos.

But from kubernetes version 1.18+ we see the metadata.managedFields[] section specified in the @vijaypsamy question. In the following image you will se the output of the same command $ kubectl get po nginx-pod -o yaml in a kubernetes version 1.19 cluster:

I am preparing for the CKA and trying to get the speed required with imperative commands for the exam, but certainly trying to get rid of those lines corresponding to metadata.managedFields[] slow down my speed.

Is there any workaround (flag) to obtain a cleaner template when using -o yaml?

@mmumshad maybe you know some tip for this?

Hello, @andrescaroc
Actually he is talking about one of the video there is used only necessary fields to know the Pod spec.

kind: Pod
apiVersion: v1
metadata:
  name: xyz
spec:
 containers:
  - image: busybox
    name: xyz

In the above spec, They didn’t added manageFields because it’s lengthy and will confuse.

You can use vi/vim editor, search string to search particular string in the yaml file and If you wants to delete those fields you can do with the dd in the vi/vim editor.

You can use kubectl-neat third party tool to remove those fields but that’s not allowed in the Exam.
You have to play with the only kubectl command.