<p>I'm trying to get the value of a node annotation with kubernetes python client.</p>

<p>This code print all the annotations for nodes with etcd nodes :</p>

<pre><code>#!/usr/bin/python

from kubernetes import client, config

def main():
    config.load_kube_config("./backup_kubeconfig_prod")
    label_selector = 'node-role.kubernetes.io/etcd'

    v1 = client.CoreV1Api()
    print("Listing nodes with their IPs:")
    ret = v1.list_node(watch=False, label_selector=label_selector)

    for i in ret.items:
      print(i.metadata.annotations)

if __name__ == '__main__':
    main()
</code></pre>

<p>Output example :</p>

<pre><code>{'flannel.alpha.coreos.com/kube-subnet-manager': 'true', 'flannel.alpha.coreos.com/backend-type': 'vxlan', 'flannel.alpha.coreos.com/backend-data': '{"VtepMAC":"96:70:f6:ab:4f:30"}', 'rke.cattle.io/internal-ip': '1.2.3.4', 'volumes.kubernetes.io/controller-managed-attach-detach': 'true', 'flannel.alpha.coreos.com/public-ip': '1.2.3.4', 'rke.cattle.io/external-ip': '1.2.3.4', 'node.alpha.kubernetes.io/ttl': '0'}
</code></pre>

<p>How can I print the value of <code>flannel.alpha.coreos.com/public-ip</code> for example ?</p>

<p>Data in <code>i.metadata.annotations</code> are dictionary type. </p>

<p>You can print the value of the key <code>flannel.alpha.coreos.com/public-ip</code> using:</p>

<pre><code>print(i.metadata.annotations["flannel.alpha.coreos.com/public-ip"])
</code></pre>
