kubernetes endpoint 代码阅读

本文介绍了Kubernetes Endpoint控制器的工作原理,包括常量参数、执行流程及syncService的详细分解。主要内容涉及Endpoint资源的最大地址数限制,并发同步的配置,以及如何处理服务与Endpoint的同步,特别是对不可用Pod的容忍策略。此外,文章还讨论了如何根据Service的配置创建和更新Endpoint,以及在不同场景下的处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打个广告,如果想旅游(国内外周边,签证,酒店,门票等)可以联系 15713688208 ,微信同号。

常量参数

首先看一些常量参数:

maxRetries: 服务在退出队列之前的重试次数。会因为限速控制器,重试间隔越来越长。

maxCapacity: 存储在endpoint资源中的最大地址数,在未来的版本中可能会超过此长度的控制。

const (
  // maxRetries is the number of times a service will be retried before it is dropped out of the queue.
  // With the current rate-limiter in use (5ms*2^(maxRetries-1)) the following numbers represent the
  // sequence of delays between successive queuings of a service.
  //
  // 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
  maxRetries = 15

  // maxCapacity represents the maximum number of addresses that should be
  // stored in an Endpoints resource. In a future release, this controller
  // may truncate endpoints exceeding this length.
  maxCapacity = 1000

  // TolerateUnreadyEndpointsAnnotation is an annotation on the Service denoting if the endpoints
  // controller should go ahead and create endpoints for unready pods. This annotation is
  // currently only used by StatefulSets, where we need the pod to be DNS
  // resolvable during initialization and termination. In this situation we
  // create a headless Service just for the StatefulSet, and clients shouldn't
  // be using this Service for anything so unready endpoints don't matter.
  // Endpoints of these Services retain their DNS records and continue
  // receiving traffic for the Service from the moment the kubelet starts all
  // containers in the pod and marks it "Running", till the kubelet stops all
  // containers and deletes the pod from the apiserver.
  // This field is deprecated. v1.Service.PublishNotReadyAddresses will replace it
  // subsequent releases.  It will be removed no sooner than 1.13.
  TolerateUnreadyEndpointsAnnotation = "service.alpha.kubernetes.io/tolerate-unready-endpoints"
)

执行流程

kube-controller-manager 中可以设置参数,在同一时间处理的endpoint数量,可以调整的更大,那么相应的就会耗费更加多的cpu和负载。

–concurrent-endpoint-syncs int32 Default: 5

The number of endpoint syncing operations that will be done concurrently. Larger number = faster endpoint updating, but more CPU (and network) load

用于批量pod更新,默认为0值,表示每个pod都会触发更新。

–endpoint-updates-batch-period duration

The length of endpoint updates batching period. Processing of pod changes will be delayed by this duration to join them with potential upcoming updates and reduce the overall number of endpoints updates. Larger number = higher endpoint programming latency, but lower number of endpoints revision generated

// EndpointControllerConfiguration contains elements describing EndpointController.
type EndpointControllerConfiguration struct {
// concurrentEndpointSyncs is the number of endpoint syncing operations
// that will be done concurrently. Larger number = faster endpoint updating,
// but more CPU (and network) load.
ConcurrentEndpointSyncs int32


// EndpointUpdatesBatchPeriod can be used to batch endpoint updates.
// All updates of endpoint triggered by pod change will be delayed by up to
// 'EndpointUpdatesBatchPeriod'. If other pods in the same endpoint change
// in that period, they will be batched to a single endpoint update.
// Default 0 value means that each pod update triggers an endpoint update.
EndpointUpdatesBatchPeriod metav1.Duration
}

开始执行endpoint进行调用,传入响应的参数。

func startEndpointController(ctx ControllerContext) (http.Handler, bool, error) {
  go endpointcontroller.NewEndpointController(
    ctx.InformerFactory.Core().V1().Pods(),
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值