Home > Mobile >  How to verify which node is master with kubernetes API python
How to verify which node is master with kubernetes API python

Time:12-13

I'm currently using Kubernetes Python Client V1 API. Since there is a way to list node details but I could not find which one is master

k8s_api = client.CoreV1Api()
logger.info("Getting k8s nodes...")
response = k8s_api.list_node()

CodePudding user response:

k8s_api = client.CoreV1Api()
response = k8s_api.list_node()

# Loop through the nodes and check for the master node label
for node in response.items:
    if "node-role.kubernetes.io/master" in node.metadata.labels:
        print(f"Master node: {node.metadata.name}")
  • Related