我试图用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
的值?在
i.metadata.annotations
中的数据是字典类型。在可以使用以下方法打印键
flannel.alpha.coreos.com/public-ip
的值:相关问题 更多 >
编程相关推荐