kubernetes python客户端获取特定注释的值

2024-06-02 20:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用kubernetespython客户机获取节点注释的值。在

此代码打印带有etcd节点的节点的所有注释:

#!/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()

输出示例:

^{pr2}$

例如,如何打印flannel.alpha.coreos.com/public-ip的值?在


Tags: clientconfignode客户机节点mainselectorkubernetes
1条回答
网友
1楼 · 发布于 2024-06-02 20:33:13

i.metadata.annotations中的数据是字典类型。在

可以使用以下方法打印键flannel.alpha.coreos.com/public-ip的值:

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

相关问题 更多 >