Nodes in kubernetes
Tags: kubernetes, bash, webdev, devops
Published: 2023-01-14 20:29:53


![Kubernetes](https://higordiego.com.br/posts/img/k8s/no.png)
## Introduction

Kubernetes manages its workload by allocating containers in **pods** in order to run them on nodes. A node can be a physical or virtual machine.
depending on your cluster configuration. Each node contains its [control plane](https://higordiego.com.br/posts/k8s-introduction/#control-panel) containing the necessary resources to run its **pods**. The master type machine is responsible for controlling the nodes.

The components included in the node are [kubelet](https://higordiego.com.br/posts/k8s-introduction/#kubelet), [container runtime](https://higordiego.com.br/posts/k8s- introduction/#container-runtime) and [kube-proxy](https://higordiego.com.br/posts/k8s-introduction/#kube-proxy).



## Management of nodes

There are two ways to have a node added to [Kube-apiserver](https://higordiego.com.br/posts/k8s-introduction/#kube-apiserver).

* [kubelet](https://higordiego.com.br/posts/k8s-introduction/#kubelet) registering on [control plane](https://higordiego.com.br/posts/k8s-introduction/# control-panel).
* Manually, creating your record based on the node-type object configuration.


When creating a node-type object, the [control plane](https://higordiego.com.br/posts/k8s-introduction/#control-panel) is responsible for validating, if correct, it creates it. Below is an example of [json](https://pt.stackoverflow.com/questions/4042/o-que-%C3%A9-json-para-que-serve-e-como-funciona) for creation.

```json
{
     "kind": "Node",
     "apiVersion": "v1",
     "metadata": {
     "name": "10.20.10.125",
     "labels": {
       "name": "creating_node_k8s"
     }
   }
}
```

After registering the node in kubernetes, the kubelet validates that it was created with its corresponding `metada.data`. If the node is available, it is able to receive **pods** creations, otherwise it will be ignored until it is ready
to receive the new cargo.

When the created node is unavailable, the form of [loop](https://pt.wikipedia.org/wiki/Loop_(programa%C3%A7%C3%A3o)) will always be checked to identify a new status.
If you do not want to follow the standard routine, it will have to be deleted manually.


### Node and its exclusives

Each node has its identification name, and if there is a repetition of the same, there may be duplication of the configuration, and with that, end up generating difficulty in updating data for the node, making it necessary to exclude one of the nodes in duplicate, in order to be able to create a node with your modifications.

There are some commands to register the node in the kubelet, as follows:

* `--kubeconfig` this flag performs data authentication in [Kube-apiserver](https://higordiego.com.br/posts/k8s-introduction/#kube-apiserver).
* `--cloud-provider` this flag reads data from your [cloud-controller-manager](http://localhost:1313/posts/k8s-introduction/#cloud-controller-manager).
* `--register-node` this flag performs self-registration in [Kube-apiserver](https://higordiego.com.br/posts/k8s-introduction/#kube-apiserver).
* `--node-up` this flag informs the physical address the famous [ip](https://canaltech.com.br/software/o-que-e-ip/) of the node.
* `--node-status-update-frequency` this flag tells [kubelet](https://higordiego.com.br/posts/k8s-introduction/#kubelet) how often the health of the environment will be checked at the.


To create nodes, the administrator has free access to handle (manually) using the kubectl tool.

### *What is kubectl ?*

Kubectl is a command-line tool for managing Kubernetes clusters. To be able to access the cluster, you will need an access file located in the `$HOME/.kube` path.
If this file is in another location, use the following command:

``` shell
kubectl --kubeconfig "file path"
```

We can install the tools on platforms [GNU/Linux](https://www.gnu.org/gnu/linux-and-gnu.pt-br.html), [MacOS](https://www.apple.com /br/macos) and [Windows](https://www.microsoft.com/pt-br/windows), to install their respective OS.

For installation on [GNU/Linux](https://www.gnu.org/gnu/linux-and-gnu.pt-br.html) follow the commands below:

``` shell
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/ kubectl
```


``` shell
chmod +x ./kubectl
```

``` shell
sudo mv ./kubectl /usr/local/bin/kubectl
```

``` shell
kubectl version --client
```

For installation on [MacOS](https://www.apple.com/br/macos) follow the commands below:

``` shell
sudo brew install kubectl
```

``` shell
kubectl version --client
```

For installation on [Windows](https://www.microsoft.com/en-us/windows) [click here](https://dl.k8s.io/release/v1.22.0/bin/windows/amd64 /kubectl.exe).

To learn more about the installation we have the official documentation [click here](https://kubernetes.io/docs/tasks/tools/).

With kubectl we can modify the node objects, creating a node manually using the `--register-node=false` flag. Each node has its status that contains some information, which are:

* **Address**: The use of this field changes depending on your cloud provider or manual configuration;
   * **Hostname**: this field is used to indicate the name of the node, which can be changed using the following flag `--hostname-override;
   * **ExternalIP**: this field is to indicate the external IP of your cluster;
   * **InternalIP**: this field is to indicate the internal IP of your cluster;
* **Conditions**: this field is responsible for signaling the status condition of the running nodes;
   * **Ready**: this field signals whether or not the node is in compliance with the value (`True` or `False`);
   * **DiskPressure**: this field indicates whether it contains space on the hard disk with the value (`True` or `False`);
   * **MemoryPressure**: this field signals whether it contains space in memory with the value (`True` or `False`);
   * **PIDPressure**: this field signals if there are many processes in the node with the value (`True` or `False`);
   * **NetworkUnavailable**: this field signals whether the node's network is configured with a value (`True` or `False`);
* **Capacity and Allocatable**: this field determines the amount of resources that are available on the node, such as CPU, memory and the amount of pods that fit on the node;
* **Info**: this field determines information about the nodes, for example: kernel version, container runtime and data about the node's operating system.

## Heartbeats

This resource is responsible for validating the availability of the nodes, in order to identify computational failures, and to act when they occur. Thus, there are two forms for the heartbeats, which are:

* Updates with the status of a node;
* With *Lease* in its namespace in kube-node-lease and each node has its own object.


The kubelet is responsible for updating and creating the `.status` of the nodes when there are changes.

The interval for updating the `.status` of the node by default is 5 minutes, while the unreachable nodes are only 40 seconds.


So that's it guys, I hope you enjoyed it and until next time!

### References
https://kubernetes.io/docs/concepts/architecture/nodes/#node-controller
https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/lease-v1/
https://livro.descomplicandokubernetes.com.br/pt/day_one/descomplicando_kubernetes.html