<p>Now i have Pods as Kubernetes structs wiht the help of the command</p>
<pre><code>pods , err := clientset.CoreV1().Pods(&quot;namespace_String&quot;).List(context.TODO(), metav1.ListOptions{})
</code></pre>
<p>now i do i get it as individual yaml files
which command should i use</p>
<pre><code>for i , pod := range pods.Items{
    if i==0{
        t := reflect.TypeOF(&amp;pod)
        for j := 0; j&lt;t.NumMethod(); j++{
            m := t.Method(j)
            fmt.Println(m.Name)
}
}
}
</code></pre>
<p>this function will print the list of functions in the pod item which should i use</p>
<p>Thanks for the answer</p>

Pradeep Padmanaban C
<p>The <code>yaml</code> is just a representation of the Pod object in the kubernetes internal storage in etcd. With your <code>client-go</code> what you have got is the <code>Pod</code> instance, of the type <code>v1.Pod</code>. So you should be able to work with this object itself and get whatever you want, for example <code>p.Labels()</code> etc. But if for some reason, you are insisting on getting a yaml, you can do that via:</p>
<pre><code>import (
  &quot;sigs.k8s.io/yaml&quot;
)

b, err := yaml.Marshal(pod)
if err != nil {
  // handle err
}
log.Printf(&quot;Yaml of the pod is: %q&quot;, string(b))

</code></pre>
<p>Note that <code>yaml</code> library coming here is not coming from <code>client-go</code> library. The documentation for the <code>yaml</code> library can be found in: <a href="https://pkg.go.dev/sigs.k8s.io/yaml#Marshal" rel="nofollow noreferrer">https://pkg.go.dev/sigs.k8s.io/yaml#Marshal</a></p>
<p>Instead of <code>yaml</code> if you want to use <code>json</code>, you can simply use the <code>Marshal</code> function <a href="https://pkg.go.dev/k8s.io/apiserver/pkg/apis/example/v1#Pod.Marshal" rel="nofollow noreferrer">https://pkg.go.dev/k8s.io/apiserver/pkg/apis/example/v1#Pod.Marshal</a>  provided by the <code>v1.Pod</code> struct itself, like any other Go object.</p>
