Node node articles of Kubernetes study notes (4)

1. Node concept

Nodes are working machines in a Kubernetes cluster. They are working units, which can be physical machines, virtual machines, or cloud server instances.
Kubernetes executes workloads by placing containers into Pods that run on Nodes. Each node contains all the services and configurations required to run a Pod.

2. Node management

Node is not created by the Kubernetes cluster in essence, Kubernetes only manages the resources on the Node (such as Pod, Deployment).

2.1. How to add nodes:

2.1.1 The kubelet on the node performs automatic registration to the control plane;

2.1.2. Only use the resource list to create a Node object (the Node object must meet all the requirements for running Pod).

# 示例
{
    
    
  "kind": "Node",
  "apiVersion": "v1",
  "metadata": {
    
    
    "name": "192.168.1.10", # 节点的IP地址
    "labels": {
    
    
      "name": "k8s-node01" 
    }
  }
}

When using the resource list method to create a Node resource object, kubernetes will internally create a Node object as a representation of the node. Kubernetes checks that the metadata.name field used by the kubelet to register the node with the API server
matches. If the node is monitored, the node can be used to run pods, otherwise all cluster activity ignores the node until the node becomes healthy.

2.2. Node name uniqueness

The name of the node is used to identify the Node object. No two Nodes can use the same name at the same time. Kubernetes also assumes that resources with the same name are the same object. In the case of Node, it is implicitly assumed that instances with the same name will have the same state (such as network configuration, root disk contents) and properties like node labels. This can lead to inconsistent system state when a node is changed but its name is unchanged. If a Node needs to be replaced or changed a lot, the existing Node object needs to be removed from the API server, and then re-added after the update.

2.3. Node expansion and contraction

2.3.1. Expansion

In the actual production system, when the capacity of cluster nodes is insufficient, it is necessary to add new nodes (with all the services required for Pod operation) to the cluster to achieve horizontal expansion of the cluster to achieve the purpose of capacity expansion.
2.3.2. Scale down
You can delete the node node to achieve the purpose of shrinking capacity. Before deleting, you need to expel all pods on the node and set the node as unschedulable

kubectl delete node k8s-node1
2.4. Node common operations

2.4.1 Setting the node as unschedulable

kubectl cordon k8s-node1

2.4.2 Setting the node as schedulable

kubectl uncordon k8s-node1

2.4.3 Evicting Pods on Nodes

kubectl drain k8s-node1

2.4.4 Labeling nodes

kubectl label node k8s-node1 key1=value1

2.4.5 Delete node labels
To delete a label, you only need to specify the key name of the label at the end of the command line and add a minus sign:

kubectl label node k8s-node1 key1-

3. Node state

A node's state contains the following information:

  • Addresses
  • Condition
  • Capacity and Allocatable
  • Information (Info)
3.1.addresses

addresses records the address list of reachable nodes, and generally can contain the following attributes:

  • hostname (host name)
  • externalip (external network IP)
  • internalip (intranet IP)
3.2.Condition

condition describes a series of states when the node is running. Generally have the following status:

  • Ready True indicates that the node is healthy and can accept Pod scheduling requests, and can carry Pods, and False indicates that the node is unhealthy and cannot accept Pod scheduling requests
  • Unknown means that the node did not send the last heartbeat to the node controller within the specified time, and the node lost connection with the cluster. At this time, it means that the node is abnormal
  • DiskPressure True indicates disk size pressure (less disk free capacity)
  • MemoryPressure True indicates memory pressure (memory capacity is too small)
  • PIDPressure True indicates that there are a large number of processes on the node
  • NetworkUnavailable True indicates that the node's network is misconfigured
3.3. Capacity and Allocatable

These two values ​​describe the resources available on the node: CPU, memory, and the maximum number of pods that can be scheduled on the node.
The fields in the capacity block indicate the total amount of resources owned by the node, and the Allocatable block indicates the amount of resources on the node that can be consumed by ordinary pods.

3.4. Information (info)

The info value is the general information of the node, such as the kernel version, kubernetes version (kubelet and kube-proxy version), container runtime details, and the operating system used by the node. The kubelet collects this information from the nodes and publishes it to the kubernetes api

おすすめ

転載: blog.csdn.net/Habo_/article/details/127089889
おすすめ