datadog 的增强 daemonset

125 阅读2分钟

datadog 是一个可观测性厂商,它需要安装一个 agent 在每台 k8s 机器上以收集数据。

datadog 专门为该 agent 开发了一个 daemonset 以运维它。

extend daemonset 是 datadog 提供的一个高级 daemonset。 github.com/DataDog/ext…

正常的 daemonset 确保在 k8s 的所有机器上运行一个守护进程(采集日志等)kubernetes.io/docs/concep…

它们的更新是滚动更新,一次下线一个机器上的 daemonset,然后运行新版本的 daemonset。kubernetes.io/docs/tasks/…

而在 extend daemonset 中:

  • canary:仅使用少数节点部署新版本的 DaemonSet。
  • 自定义滚动更新:改进 Kubernetes 中可用的默认滚动更新逻辑batch/v1 Daemonset

canary

在 canary 阶段,会运行 replicas 数量的 pod,经过 duration 时间之后,认为新版本的服务重启次数等符合预期,才会过渡到自定义的滚动更新阶段。

可以通过 nodeSelector 选择在低负载或者优先级的服务上运行 canary 镜像。

可以通过 NodeAntiAffinityKeys 确保 canary node 分布均衡,比如总共更新四个,那么在两个服务之间各更新一个。

Replicas     *intstr.IntOrString   `json:"replicas,omitempty"`
Duration     *metav1.Duration      `json:"duration,omitempty"`
NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
// +listType=set
NodeAntiAffinityKeys []string                                      `json:"nodeAntiAffinityKeys,omitempty"`
AutoPause            *ExtendedDaemonSetSpecStrategyCanaryAutoPause `json:"autoPause,omitempty"`
AutoFail             *ExtendedDaemonSetSpecStrategyCanaryAutoFail  `json:"autoFail,omitempty"`
// NoRestartsDuration defines min duration since last restart to end the canary phase.
NoRestartsDuration *metav1.Duration `json:"noRestartsDuration,omitempty"`
// ValidationMode used to configure how a canary deployment is validated. Possible values are 'auto' (default) and 'manual'
ValidationMode ExtendedDaemonSetSpecStrategyCanaryValidationMode `json:"validationMode,omitempty"`

rolling update

跟默认的滚动更新策略相比,datadog 提供的滚动更新主要在于支持并发更新以减少更新所耗费的时间。

普通的 daemonset 提供的 rolling update strategy:

 maxUnavailable: 1  # 最大不可用 Pod 数量

extend daemonset:

  • MaxUnavailable,跟原生 daemonset 的参数一样。
  • MaxParallelPodCreation, 提供并发更新 pod 的能力,可以减少 daemonset 的更新时间。
  • SlowStartAdditiveIncrease,用来控制初始更新的 pod 的数量,配合 SlowStartIntervalDuration 用于线性增长更新数量。
  • SlowStartIntervalDuration,每轮递增的间隔时间,比如每 1分钟增长 SlowStartAdditiveIncrease。比如第一次更新了 5 个,那么如果当前比第一次更新时间已经过去了一分钟,那么就更新十个,直到触发 MaxParallelPodCreation。
  • MaxPodSchedulerFailure,由于资源限制导致的 pod 无法调度的情况。
// The maximum number of DaemonSet pods that can be unavailable during the
// update. Value can be an absolute number (ex: 5) or a percentage of total
// number of DaemonSet pods at the start of the update (ex: 10%). Absolute
// number is calculated from percentage by rounding up.
// This cannot be 0.
// Default value is 1.
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
// MaxPodSchedulerFailure the maxinum number of not scheduled on its Node due to a
// scheduler failure: resource constraints. Value can be an absolute number (ex: 5) or a percentage of total
// number of DaemonSet pods at the start of the update (ex: 10%). Absolute.
MaxPodSchedulerFailure *intstr.IntOrString `json:"maxPodSchedulerFailure,omitempty"`
// The maxium number of pods created in parallel.
// Default value is 250.
MaxParallelPodCreation *int32 `json:"maxParallelPodCreation,omitempty"`
// SlowStartIntervalDuration the duration between to 2
// Default value is 1min.
SlowStartIntervalDuration *metav1.Duration `json:"slowStartIntervalDuration,omitempty"`
// SlowStartAdditiveIncrease
// Value can be an absolute number (ex: 5) or a percentage of total
// number of DaemonSet pods at the start of the update (ex: 10%).
// Default value is 5.
SlowStartAdditiveIncrease *intstr.IntOrString `json:"slowStartAdditiveIncrease,omitempty"`