Kubernetes Node Status While it is being created

225 Views Asked by At

Getting the Kubernetes nodes information.

var client = MinikubeTests.CreateClient();
var node = client.CoreV1.ListNode().Items.First();
var nodeName = node.Metadata.Name;

Getting the node conditions as:

foreach(var nodeStatus in node.Status.Conditions) {
    Console.WriteLine("{0} - {1}", nodeStatus.Type, nodeStatus.Status);
}

enter image description here

Here the node ready status is true. How can we get the status while the node is being created?

1

There are 1 best solutions below

4
On

Ok I see what your getting at . Use NodeCondition. It provides information about various conditions or states of a node, such as whether it is ready or not . NodeCondition may not immediately indicate the readiness status as True because it takes some time for the node to become fully operational.

Firstly check if the creating condition is present and supported by your cluster at all . presence of a Creating condition in the node status may depend on the version and configuration of your Kubernetes cluster. This condition is not a standard condition type and may not be present in all clusters. If your cluster does not include this condition, you can use the Ready condition to determine if the node is ready or not and to that extent you will loose granularity .

check if the Creating condition is present in the node status by retrieving the node information and checking the Conditions property of the node’s status.

var client = MinikubeTests.CreateClient();
var node = client.CoreV1.ListNode().Items.First();
var nodeName = node.Metadata.Name;

// Check if the node has a Creating condition
var creatingCondition = node.Status.Conditions.FirstOrDefault(c => c.Type == "Creating");
if (creatingCondition != null)
{
    Console.WriteLine("Node has a Creating condition.");
}
else
{
    Console.WriteLine("Node does not have a Creating condition.");
}

If this condition is present, it means that the node has a Creating condition. Otherwise, it means that the node does not have this condition. That's regardless of whether the node is ready or not. It does this by retrieving the node information and checking the Conditions property of the node’s status to see if it includes a condition with Type set to "Creating".

If the creating condition is present then run the below code to catch if the node is in that condition Again This condition may not be present in all Kubernetes clusters, as it is not a standard condition type. If your cluster does not include this condition, you can use the Ready condition to determine if the node is ready or not.

var client = MinikubeTests.CreateClient();
var node = client.CoreV1.ListNode().Items.First();
var nodeName = node.Metadata.Name;

// Check if the node is in the process of being created
var creatingCondition = node.Status.Conditions.FirstOrDefault(c => c.Type == "Creating");
if (creatingCondition != null && creatingCondition.Status == "True")
{
    Console.WriteLine("Node is still being created.");
}
else
{
    // The node is not being created, check if it is ready
    var readyCondition = node.Status.Conditions.FirstOrDefault(c => c.Type == "Ready");
    if (readyCondition != null && readyCondition.Status == "True")
    {
        Console.WriteLine("Node is ready.");
    }
    else
    {
        Console.WriteLine("Node is not ready.");
    }
}