kubelet上报心跳机制

在k8s v1.13之前,kubelet启动协程定时上报状态。

参数

含义

默认间隔时间

--node-status-update-frequency

上报NodeStatus间隔时间

10s

--node-monitor-grace-period

判定Node是NotReady间隔时间

40s

--pod-eviction-timeout

Node NotReady后驱逐Pod的时间间隔

5m

 

k8s v1.13引入了NodeLease,k8s v1.17 stable。在kube-node-lease namespace下,每个节点都有一个Lease对象。
NodeStatus和NodeLease都记录节点的心跳信号,协同工作逻辑如下:
1. kubelet定期更新自己的lease对象,默认10秒。
2. kubelet定期(默认为10秒)计算一次NodeStatus,独立于上报流程;只有发生有意义的变化或者不上报持续时间超过了参数node-status-update-period(默认5m)时,kubelet才上报NodeStatus。


无论是NodeStatus对象还是NodeLease对象的更新,NodeController都视为kubelet在上报心跳。NodeLease对象比NodeStatus对象小很多,大幅降低了NodeStatus的更新频率,显著降低Etcd存储压力。

 

NodeLease结构体

type Lease struct {
  metav1.TypeMeta `json:",inline"`
  // Standard object's metadata.
  // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
  // +optional
  ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`

  // Specification of the Lease.
  // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
  // +optional
  Spec LeaseSpec `json:"spec,omitempty"`
}

type LeaseSpec struct {
  HolderIdentity       string           `json:"holderIdentity"`
  LeaseDurationSeconds int32            `json:"leaseDurationSeconds"`
  AcquireTime          metav1.MicroTime `json:"acquireTime"`
  RenewTime            metav1.MicroTime `json:"renewTime"`
  LeaseTransitions     int32            `json:"leaseTransitions"`
}

 

查看lease内容

 

参考资料

Kubelet 状态更新机制
What is the "kube-node-lease" namespace for?
kubernetes资源管理
Efficient Node Heartbeats

posted on 2023-02-03 22:18  王景迁  阅读(721)  评论(0编辑  收藏  举报

导航