<p>I have a Docker image that contains an application in python, running in Kubernetes as a deployment, I want to pass to that application some data. I used env vars but I would like to use annotations but I'm not sure how to read them, I saw that <code>V1ObjectMeta</code> has a field called <code>annotations</code> but I'm a bit lost of how to call it.</p>
<p>For example:</p>
<p>If my pod has this:</p>
<pre><code>template:
  metadata:
    annotations:
      foo: &quot;var&quot;
</code></pre>
<p>How to read <code>foo: var</code> using the python program that is running inside the pod using the Kubernetes library?</p>

<p>All you need is to get the pod object from Kubernetes API. It has the same structure as in <code>YAML</code> format, so once you have the data, the rest is trivial. See below:</p>
<pre class="lang-py prettyprint-override"><code>from kubernetes import client, config

config.load_incluster_config()
c = client.CoreV1Api()

pod = c.read_namespaced_pod(name=&quot;my-pod-name&quot;, namespace=&quot;my-namespace&quot;)

print(pod.metadata.annotations[&quot;foo&quot;])
</code></pre>
