<p>I am trying to add a new key value pair to existing set of Annotations to a running Pod using the below example code:</p>
<pre><code>import (
        &quot;fmt&quot;
        &quot;context&quot;
        metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
        &quot;k8s.io/client-go/tools/clientcmd&quot;
        &quot;k8s.io/client-go/kubernetes&quot;
        &quot;k8s.io/klog&quot;
)

const ( 
        configPath = &quot;/home/test/.kube/config&quot;
)
func main() {
        client, _ := connect()
        pod, _ := client.CoreV1().Pods(&quot;default&quot;).Get(context.TODO(), &quot;nginx-pod&quot;,metav1.GetOptions{})
        fmt.Println(pod.Name)
        annotations := map[string]string{
                &quot;foo&quot;:&quot;bar&quot;,
        }
        pod.SetAnnotations(annotations)
        for name, value := range pod.GetAnnotations() {
                fmt.Println(&quot;name := &quot;, name, &quot;value =&quot;, value)
        }

}

func connect() (*kubernetes.Clientset, error) {
        restconfig, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, configPath)
        if err != nil {
                klog.Exit(err.Error())
        }
        clientset, err := kubernetes.NewForConfig(restconfig)
        if err != nil {
                klog.Exit(err.Error())
        }
       return clientset, nil
}
</code></pre>
<p>when i run the above code and use &quot;oc describe pods/nginx-pod i don't see the annotation &quot;foo: bar&quot; under the annotations.
What's the right way to add New Annotations to an existing pod.</p>

<p>You're going to want something along the lines:</p>
<pre class="lang-golang prettyprint-override"><code>...
pod.SetAnnotations(annotations)
client.
  CoreV1().
  Pods(&quot;default&quot;).
  Update(context.TODO(), pod, metav1.UpdateOptions{})
</code></pre>
<p>See: <a href="https://pkg.go.dev/k8s.io/client-go@v0.23.1/kubernetes/typed/core/v1#PodInterface" rel="nofollow noreferrer">PodInterface</a></p>
