Kubernetes 垂直自動(dòng)伸縮走向何方?
目前 Kubernetes 的 Pod 水平自動(dòng)伸縮(HPA,Horizontal Pod Autoscaler)已在業(yè)界廣泛應(yīng)用。但對(duì)一些特殊的 Pod(如一些有狀態(tài)的 Pod),HPA 并不能很好地解決資源不足的問題。這就引出 Pod 垂直自動(dòng)伸縮(VPA,Vertical Pod Autoscaler),本文主要介紹 Kubernetes 社區(qū)對(duì) Pod 垂直自動(dòng)伸縮組件的開發(fā)規(guī)劃。
VPA定義
垂直自動(dòng)伸縮(VPA,Vertical Pod Autoscaler) 是一個(gè)基于歷史數(shù)據(jù)、集群可使用資源數(shù)量和實(shí)時(shí)的事件(如 OMM, 即 out of memory)來自動(dòng)設(shè)置Pod所需資源并且能夠在運(yùn)行時(shí)自動(dòng)調(diào)整資源基礎(chǔ)服務(wù)。
介紹
背景
- 計(jì)算資源
- 資源服務(wù)質(zhì)量
- 準(zhǔn)入控制器
- 外部準(zhǔn)入webhooks
目標(biāo)
VPA有兩個(gè)目標(biāo):
- 通過自動(dòng)配置資源請(qǐng)求來減少運(yùn)維成本。
- 在提高集群資源利用率的同時(shí)最小化容器出現(xiàn)內(nèi)存溢出或 CPU 饑餓的風(fēng)險(xiǎn)。
相關(guān)特性
水平自動(dòng)伸縮(Horizontal Pod Autoscaler,HPA)
HPA 是基于實(shí)時(shí)的CPU利用率或者其他的一些特定信號(hào)動(dòng)態(tài)調(diào)整 Replication controller 中 Pod 數(shù)量的基礎(chǔ)服務(wù)。
通常用戶在無(wú)狀態(tài)的工作負(fù)載時(shí)選用 HPA,在有狀態(tài)的工作負(fù)載時(shí)選用 VPA。也有一些場(chǎng)景下會(huì)混合使用。
集群自動(dòng)伸縮(Cluster Autoscaler)
集群自動(dòng)伸縮基于集群整體的資源利用率動(dòng)態(tài)調(diào)整 Kubernetes 集群的大小。
集群自動(dòng)伸縮、HPA 和 VPA 提供了一個(gè)完整的自動(dòng)伸縮解決方案。
初始資源(Initial resources)
初始資源基于歷史資源利用率提供初始資源請(qǐng)求,它僅僅在Pod創(chuàng)建時(shí)觸發(fā),VPA打算繼承使用這個(gè)特性。
原地升級(jí)(In-place updates)
原地升級(jí)是一個(gè)計(jì)劃中的功能,在節(jié)點(diǎn)上有足夠資源的情況下,原地升級(jí)無(wú)需殺死容器就能夠調(diào)整已存在容器的資源的請(qǐng)求和限制。
VPA將從這種能力中受益匪淺,但它不被視為最小可行產(chǎn)品 ( inimum Viable Product, MVP) 的阻擋者。
資源估計(jì)(Resource estimation)
資源估計(jì)是另外一個(gè)計(jì)劃中的功能,它可以通過暫時(shí)回收運(yùn)行中容器的暫未使用的資源來提高資源利用率。
資源估計(jì)與 VPA 的不同在于它基于的時(shí)間表比較短(僅基于本地的短期的歷史數(shù)據(jù)),回收以后再提供的質(zhì)量低,不提供初始資源預(yù)測(cè)。VPA 和資源估計(jì)是互補(bǔ)的。
需求
功能
- VPA 能夠在 Pod 提交時(shí)設(shè)置容器的資源(CPU和內(nèi)存的請(qǐng)求和限制)。
- VPA能夠調(diào)整已存在的 Pod 的容器資源,特別是能夠?qū)?CPU 饑餓和內(nèi)存溢出等事件作出響應(yīng)。
- 當(dāng) VPA 重啟 Pod 時(shí),它必須考慮中斷服務(wù)的成本。
- 用戶能夠配置 VPA 的在資源上的固定限制,特別是最小和最大資源請(qǐng)求。
- VPA 要與 Pod 控制器兼容,最起碼要與
- Deployment
兼容。特別地:
- 資源更新的時(shí)候不能干擾 spec 更新或和 spec 更新沖突。
- 在已有的部署中,能夠滾動(dòng)更新 VPA 的策略。
- 在創(chuàng)建 Pod 時(shí)能夠盡快開始遵循 VPA 策略,特別是對(duì)于一些只有VPA策略應(yīng)用以后才能被調(diào)度的 Pod 。
可用性
重量級(jí)的組件(數(shù)據(jù)庫(kù)或推薦器)出故障不會(huì)阻塞重新創(chuàng)建已存在的 Pod 。Pod 創(chuàng)建路徑非常關(guān)鍵的組件必須設(shè)計(jì)成高可用。
可擴(kuò)展性
在原地升級(jí)組件開發(fā)好后, VPA 能夠使用它。
設(shè)計(jì)
綜述
- 提出新的API資源: VerticalPodAutoscaler 。它包括一個(gè)標(biāo)簽識(shí)別器 label selector(匹配Pod)、資源策略 resources policy(控制VPA如何計(jì)算資源)、更新策略 update policy(控制資源變化應(yīng)用到Pod)和推薦資源信息。
- VPA Recommender 是一個(gè)新的組件,它考慮集群中來自 Metrics Server 的所有 Pod 的資源利用率信號(hào)和內(nèi)存溢出事件。
- VPA Recommender 會(huì)監(jiān)控所有 Pod,為每個(gè) Pod 持續(xù)計(jì)算新的推薦資源,并將它們存儲(chǔ)到 VPA Object 中。
- VPA Recommender 會(huì)暴露一個(gè)同步 API 獲取 Pod 詳細(xì)信息并返回推薦信息。
- 所有的 Pod 創(chuàng)建請(qǐng)求都會(huì)通過 VPA Admission Controller。如果 Pod 與任何一個(gè) VPA 對(duì)象匹配,那么 Admission controller 會(huì)依據(jù) VPA Recommender 推薦的值重寫容器的資源。如果 Recommender 連接不上,它將會(huì)返回 VPA Object 中緩存的推薦信息。
- VPA Updater 是負(fù)責(zé)實(shí)時(shí)更新 Pod 的組件。如果一個(gè) Pod 使用 VPA 的自動(dòng)模式,那么Updater 會(huì)依據(jù)推薦資源來決定如何更新。在 MVP 模式中,這需要通過刪除 Pod 然后依據(jù)新的資源重建 Pod 來實(shí)現(xiàn),這種方法需要 Pod 屬于一個(gè) Replica Set(或者其他能夠重新創(chuàng)建它的組件)。在未來,Updater 會(huì)利用原地升級(jí),因?yàn)橹匦聞?chuàng)建或者重新分配Pod對(duì)服務(wù)是很有破壞性的,必須盡量減少這種操作。
- VPA 僅僅控制容器的資源請(qǐng)求,它把資源限制設(shè)置為無(wú)限,資源請(qǐng)求的計(jì)算基于對(duì)當(dāng)前和過去運(yùn)行狀況的分析。
- History Storage 是從 API Server 中獲取資源利用率信號(hào)和內(nèi)存溢出并將它們永久保存的組件。Recommender 在一開始用這些歷史數(shù)據(jù)來初始化狀態(tài)。History Storage 基礎(chǔ)的實(shí)現(xiàn)是使用 Prometheus。
體系架構(gòu)
VPA Architecture Diagram
API
我們提出了一個(gè)新的類型的API對(duì)象 VertialPodAutoscaler,它包含了擴(kuò)容的目標(biāo),也就是用于匹配 Pod 的 label seletctor 和兩個(gè)策略模塊:更新策略 update policy 和資源策略resources policy。此外他還持有 VPA 計(jì)算的最新的推薦信息。
VPA API 對(duì)象綜述
- // VerticalPodAutoscaler is the configuration for a vertical pod
- // autoscaler, which automatically manages pod resources based on historical and
- // real time resource utilization.
- type VerticalPodAutoscaler struct {
- metav1.TypeMeta
- // Standard object metadata.
- // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
- // +optional
- metav1.ObjectMeta
- // Specification of the behavior of the autoscaler.
- // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
- // +optional
- Spec VerticalPodAutoscalerSpec
- // Current information about the autoscaler.
- // +optional
- Status VerticalPodAutoscalerStatus
- }
- // VerticalPodAutoscalerSpec is the specification of the behavior of the autoscaler.
- type VerticalPodAutoscalerSpec {
- // A label query that determines the set of pods controlled by the Autoscaler.
- // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
- Selector *metav1.LabelSelector
- // Describes the rules on how changes are applied to the pods.
- // +optional
- UpdatePolicy PodUpdatePolicy
- // Controls how the autoscaler computes recommended resources.
- // +optional
- ResourcePolicy PodResourcePolicy
- }
- // VerticalPodAutoscalerStatus describes the runtime state of the autoscaler.
- type VerticalPodAutoscalerStatus {
- // The time when the status was last refreshed.
- LastUpdateTime metav1.Time
- // The most recently computed amount of resources recommended by the
- // autoscaler for the controlled pods.
- // +optional
- Recommendation RecommendedPodResources
- // A free-form human readable message describing the status of the autoscaler.
- StatusMessage string
- }
標(biāo)簽選擇 (Label Selector)
Label Selector 依據(jù)給定的VPA策略決定哪些Pod需要伸縮。Recommender 會(huì)匯聚匹配給定 VPA 的所有信號(hào),因此用戶設(shè)置標(biāo)簽來將行為類似的 pod 分組到一個(gè) VPA 下是非常重要的。
現(xiàn)在還沒有決定如何處理沖突,例如一個(gè) pod 同時(shí)被多個(gè) VPA 策略匹配。
更新策略(Update Policy)
更新策略控制了VPA如何應(yīng)用更改。在 MVP 中,它只包含一個(gè)單個(gè)字段: mode
- "updatePolicy" {
- "mode": "",
- }
mode 可以設(shè)置為三種:
- Intitial: VPA 只在創(chuàng)建 Pod 時(shí)分配資源,在 Pod 的其他生命周期不改變Pod的資源。
- Auto(默認(rèn)):VPA 在 Pod 創(chuàng)建時(shí)分配資源,并且能夠在 Pod 的其他生命周期更新它們,包括淘汰和重新調(diào)度 Pod。
- Off:VPA 從不改變Pod資源。Recommender 而依舊會(huì)在VPA對(duì)象中生成推薦信息,他們可以被用在演習(xí)中。
以下任意一個(gè)操作都可以關(guān)掉 VPA :
- 把更新策略改為 Off。
- 刪除 VPA 組件。
- 改變 Pod 的標(biāo)簽讓它不在于 VPA Label Selector 匹配。
注意:關(guān)閉 VPA 會(huì)讓 Pod 不再進(jìn)行進(jìn)一步的改變,但它不會(huì)恢復(fù)到正在Pod的最初資源狀態(tài),直到用戶手動(dòng)對(duì)它進(jìn)行更新。
- // VerticalPodAutoscalerStatus describes the runtime state of the autoscaler.
- type VerticalPodAutoscalerStatus {
- // The time when the status was last refreshed.
- LastUpdateTime metav1.Time
- // The most recently computed amount of resources recommended by the
- // autoscaler for the controlled pods.
- // +optional
- Recommendation RecommendedPodResources
- // A free-form human readable message describing the status of the autoscaler.
- StatusMessage string
- }
- // UpdateMode controls when autoscaler applies changes to the pod resources.
- type UpdateMode string
- const (
- // UpdateModeOff means that autoscaler never changes Pod resources.
- // The recommender still sets the recommended resources in the
- // VerticalPodAutoscaler object. This can be used for a "dry run".
- UpdateModeOff UpdateMode = "Off"
- // UpdateModeInitial means that autoscaler only assigns resources on pod
- // creation and does not change them during the lifetime of the pod.
- UpdateModeInitial UpdateMode = "Initial"
- // UpdateModeAuto means that autoscaler assigns resources on pod creation
- // and additionally can update them during the lifetime of the pod,
- // including evicting / rescheduling the pod.
- UpdateModeAuto UpdateMode = "Auto"
- )
- // PodUpdatePolicy describes the rules on how changes are applied to the pods.
- type PodUpdatePolicy struct {
- // Controls when autoscaler applies changes to the pod resources.
- // +optional
- UpdateMode UpdateMode
- }
資源策略(Resource Policy )
資源策略控制 VPA 如何計(jì)算推薦資源。在 MVP 中,它包含每個(gè)容器請(qǐng)求中可選的上限和下限。資源策略在后面可以被擴(kuò)展為額外的開關(guān)可以讓用戶根據(jù)他們特定的場(chǎng)景調(diào)整推薦算法。
- const (
- // DefaultContainerResourcePolicy can be passed as
- // ContainerResourcePolicy.Name to specify the default policy.
- DefaultContainerResourcePolicy = "*"
- )
- // ContainerResourcePolicy controls how autoscaler computes the recommended
- // resources for a specific container.
- type ContainerResourcePolicy struct {
- // Name of the container or DefaultContainerResourcePolicy, in which
- // case the policy is used by the containers that don't have their own
- // policy specified.
- Name string
- // Whether autoscaler is enabled for the container. Defaults to "On".
- // +optional
- Mode ContainerScalingMode
- // Specifies the minimal amount of resources that will be recommended
- // for the container.
- // +optional
- MinAllowed api.ResourceRequirements
- // Specifies the maximum amount of resources that will be recommended
- // for the container.
- // +optional
- MaxAllowed api.ResourceRequirements
- }
- // PodResourcePolicy controls how autoscaler computes the recommended resources
- // for containers belonging to the pod.
- type PodResourcePolicy struct {
- // Per-container resource policies.
- ContainerPolicies []ContainerResourcePolicy
- }
- // ContainerScalingMode controls whether autoscaler is enabled for a speciifc
- // container.
- type ContainerScalingMode string
- const (
- // ContainerScalingModeOn means autoscaling is enabled for a container.
- ContainerScalingModeOn ContainerScalingMode = "On"
- // ContainerScalingModeOff means autoscaling is disabled for a container.
- ContainerScalingModeOff ContainerScalingMode = "Off"
- )
推薦(Recommendation)
VPA 資源有一個(gè)僅輸出的字段用來保存一個(gè)由 Recommender 生成的最近的一次推薦。這個(gè)字段可以在 Recommender 暫時(shí)無(wú)法訪問時(shí)被用來獲取最近的一次推薦。這個(gè)推薦包含推薦目標(biāo)資源數(shù)量以及范圍(最大,最小),可以被 Updater 用來決定在何時(shí)更新 Pod。在資源緊缺的情況下,Updater 可能決定將 Pod 資源壓縮到推薦的最小值。范圍的寬度同樣也影響了推薦的置信區(qū)間。
- // RecommendedPodResources is the recommendation of resources computed by
- // autoscaler.
- type RecommendedPodResources struct {
- // Resources recommended by the autoscaler for each container.
- ContainerRecommendations []RecommendedContainerResources
- }
- // RecommendedContainerResources is the recommendation of resources computed by
- // autoscaler for a specific container. Respects the container resource policy
- // if present in the spec.
- type RecommendedContainerResources struct {
- // Name of the container.
- Name string
- // Recommended amount of resources.
- Target api.ResourceRequirements
- // Minimum recommended amount of resources.
- // Running the application with less resources is likely to have
- // significant impact on performance/availability.
- // +optional
- MinRecommended api.ResourceRequirements
- // Maximum recommended amount of resources.
- // Any resources allocated beyond this value are likely wasted.
- // +optional
- MaxRecommended api.ResourceRequirements
- }
準(zhǔn)入控制器(Admission Controller)
VPA Admission Controller 攔截 Pod 創(chuàng)建請(qǐng)求。如果 Pod 與 VPA 配置匹配且模式未設(shè)置為off,則控制器通過將建議的資源應(yīng)用于 Pod spec 來重寫資源請(qǐng)求。否則它會(huì)使 Pod spec保持不變。
控制器通過從 Recommender 中的 /recommendedPodResources 來獲取推薦的資源。如果呼叫超時(shí)或失敗,控制器將回退到 VPA object 中緩存的建議。如果這也不可用,則控制器允許資源請(qǐng)求傳遞最初指定的資源。
注意:將來可以通過將 Pod 標(biāo)記為 requiring VPA 來(可選)強(qiáng)制使用 VPA 。這將禁止在創(chuàng)建相應(yīng)的 VPA 配置之前調(diào)度 Pod 。如果找不到匹配的 VPA 配置,則準(zhǔn)入控制器將拒絕此類 Pod 。對(duì)于想要?jiǎng)?chuàng)建 VPA 配置并提交 Pod 的用戶來說,此功能將非常方便。
VPA 準(zhǔn)入控制器將作為外部入場(chǎng)鉤子(External Admission Hook)實(shí)施。但請(qǐng)注意,這取決于變異webhook 準(zhǔn)入控制器(Mutating Webhook Admission Controllers)。
推薦器(Recommender)
Recommender 是 VPA 的主要組成部分。它負(fù)責(zé)計(jì)算推薦的資源。在啟動(dòng)時(shí),Recommender 獲取所有 Pod 的歷史資源利用率(無(wú)論它們是否使用 VPA )以及歷史存儲(chǔ)中的 Pod OOM 事件的歷史記錄。它聚合這些數(shù)據(jù)并將其保存在內(nèi)存中。
在正常操作期間,Recommender 通過 Metrics API 從 Metrics Server 獲取資源利用率和新事件的實(shí)時(shí)更新。此外,它還可以監(jiān)視群集中的所有 Pod 和所有 VPA object 。對(duì)于由某個(gè)VPA選擇器匹配的每個(gè) Pod,Recommender 計(jì)算推薦的資源并在 VPA object 上設(shè)置推薦。
意識(shí)到每個(gè) VPA object 有一個(gè)推薦是非常重要的。用戶應(yīng)使用一個(gè) VPA 來控制具有類似資源使用模式的 Pod ,通常是一組副本或單個(gè)工作負(fù)載的分片。
Recommender 充當(dāng)了一個(gè) extension-apiserver,暴露了一個(gè)同步方法,該方法獲取 Podspec 和 Pod 元數(shù)據(jù)并返回推薦的資源。
Recommender API
- 請(qǐng)求體:
- ```go
- // RecommendationQuery obtains resource recommendation for a pod.
- type RecommendationQuery struct {
- metav1.TypeMeta
- // +optional
- metav1.ObjectMeta
- // Spec is filled in by the caller to request a recommendation.
- Spec RecommendationQuerySpec
- // Status is filled in by the server with the recommended pod resources.
- // +optional
- Status RecommendationQueryStatus
- }
- // RecommendationQuerySpec is a request of recommendation for a pod.
- type RecommendationQuerySpec struct {
- // Pod for which to compute the recommendation. Does not need to exist.
- Pod core.Pod
- }
- // RecommendationQueryStatus is a response to the recommendation request.
- type RecommendationQueryStatus {
- // Recommendation holds recommended resources for the pod.
- // +optional
- Recommendation autoscaler.RecommendedPodResources
- // Error indicates that the recommendation was not available. Either
- // Recommendation or Error must be present.
- // +optional
- Error string
- }
注意,現(xiàn)有 Pod 以及尚未創(chuàng)建的 Pod 都可以調(diào)用此 API。
更新器(Updater)
VPA Updater 是一個(gè)負(fù)責(zé)將推薦資源應(yīng)用于現(xiàn)有 Pod 的組件。它監(jiān)視集群中的所有 VPA object 和 Pod ,通過調(diào)用 Recommender API 定期獲取由 VPA 控制的 Pod 的建議。當(dāng)推薦的資源與實(shí)際配置的資源明顯不同時(shí),Updater 可能會(huì)決定更新 Pod。在 MVP 中(直到 Pod 資源的原地升級(jí)可用),這意味著需要驅(qū)逐現(xiàn)有的 Pod 然后使用推薦的資源重新創(chuàng)建它們。
Updater 依賴于其他機(jī)制(例如副本集)來重新創(chuàng)建已刪除的 Pod 。但是,它不驗(yàn)證是否實(shí)際為 Pod 配置了此類機(jī)制。這樣的檢查可以在 CLI 中實(shí)現(xiàn),并在 VPA 匹配 Pod 時(shí)警告用戶,但 Pod 不會(huì)自動(dòng)重啟。
雖然終止Pod是破壞性的并且通常是不期望的,但有時(shí)也是合理的:
- 避免 CPU 饑餓.
- 隨機(jī)降低跨多個(gè) Pod 的相關(guān) OOM 的風(fēng)險(xiǎn).
- 在長(zhǎng)時(shí)間內(nèi)節(jié)省資源.
Updater 僅在 updatePolicy.mod 設(shè)置為 Auto 時(shí)才會(huì)配置 Pod 。
根據(jù)群集的當(dāng)前狀態(tài)(例如,配額,節(jié)點(diǎn)上可用的空間或其他調(diào)度約束),Updater 還需要了解如何在將推薦應(yīng)用于Pod之前調(diào)整推薦。否則它可能會(huì)永久性地取消一個(gè) Pod 。這種機(jī)制尚未設(shè)計(jì)。
推薦計(jì)算模型(Recommendation model)
VPA控制容器的資源請(qǐng)求(內(nèi)存和 CPU)。在 MVP 中,它總是將資源限制設(shè)置為無(wú)窮大。目前尚不清楚是否存在 VPA 設(shè)定資源限制的用例。
資源請(qǐng)求是基于對(duì)容器的當(dāng)前和先前運(yùn)行以及具有類似屬性的其他容器(名稱,圖像,命令,args)的分析來計(jì)算的。推薦的模型(MVP)假設(shè)內(nèi)存和CPU消耗是獨(dú)立的隨機(jī)變量,其分布等于在過去 N 天中觀察到的分布(推薦 N 值取為 N =8 以捕獲每周峰值)。未來更先進(jìn)的模型可能會(huì)嘗試檢測(cè)趨勢(shì),周期性和其他與時(shí)間相關(guān)的模式。
對(duì)于CPU, 目標(biāo)是保證容器使用的CPU超過容器請(qǐng)求的 CPU 資源的高百分比(如95%)時(shí)間低于某個(gè)特定的閾值(如保證只有1%的時(shí)間內(nèi)容器的CPU使用高于請(qǐng)求的 CPU 資源的95%)在此模型中,“CPU 使用”定義為在短時(shí)間間隔內(nèi)測(cè)量的平均值。測(cè)量間隔越短,對(duì)尖峰,延遲敏感的工作負(fù)載的建議質(zhì)量越好。最低合理間隔為 1/min,建議為 1/sec。
對(duì)于內(nèi)存,目標(biāo)是保證在特定時(shí)間窗口內(nèi)容器使用的內(nèi)存超過容器請(qǐng)求的內(nèi)存資源的概率低于某個(gè)閾值(例如,在 24 小時(shí)內(nèi)低于 1%)。窗口必須很長(zhǎng)( ≥24h ),以確保 OOM 引起的驅(qū)逐不會(huì)明顯影響服務(wù)應(yīng)用程序的可用性和批量計(jì)算的進(jìn)度(更高級(jí)的模型可以允許用戶指定 SLO 來控制它)。
內(nèi)存溢出處理(Handling OOMs)
當(dāng)容器由于超出可用內(nèi)存而被逐出時(shí),其實(shí)際內(nèi)存要求是未知的(消耗的量顯然給出了下限)。這是通過將 OOM 事件轉(zhuǎn)換為人工內(nèi)存使用樣本來建模的,方法是將“安全邊際”乘數(shù) (“safety margin” multiplier ) 應(yīng)用于最后一次觀察到的使用情況。
歷史存儲(chǔ)(History Storage )
VPA 為歷史事件和資源利用的提供者定義數(shù)據(jù)訪問 API 。一開始,至少在資源利用部分,我們將使用 Prometheus 作為此 API 的參考實(shí)現(xiàn),歷史事件可以由另一個(gè)解決方案支持,例如,Infrastore。用戶將能夠插入自己的實(shí)現(xiàn)。
History Storage 被不斷填充實(shí)時(shí)更新的資源利用率和事件,類似于 Recommender。它至少保留8天的數(shù)據(jù)。此數(shù)據(jù)僅用于在啟動(dòng)時(shí)初始化 Recommender 。
開放問題
如果多個(gè) VPA 對(duì)象與一個(gè) Pod 匹配,如何解決沖突。
如何在將推薦應(yīng)用于特定容器之前根據(jù)集群的當(dāng)前狀態(tài)調(diào)整推薦(例如,配額,節(jié)點(diǎn)上可用的空間或其他調(diào)度約束)。
未來的工作
Pod啟動(dòng)時(shí)融入 VPA
在當(dāng)前提案中,如果在 Pod 接納時(shí)間 (Admission Time) 內(nèi) Pod 沒有匹配的 VPA 配置,則將使用最初配置的資源調(diào)度 Pod。這可能并不是用戶希望的行為。特別地,用戶可能想要?jiǎng)?chuàng)建 VPA 配置同時(shí)提交到 Pod,這會(huì)導(dǎo)致競(jìng)爭(zhēng)條件:結(jié)果取決于首先處理哪個(gè)資源(VPA 或 Pod)。
為了解決這個(gè)問題,我們建議允許使用特殊注釋(requires VPA)標(biāo)記 Pod,如果相應(yīng)的 VPA 不可用,則阻止接納控制器 (Admission Controlle) 接納Pod。
另一種方法是引入用于相同目的的VPA初始化器。
結(jié)合垂直和水平縮放
原則上,只要兩個(gè)機(jī)制在不同的資源上運(yùn)行,就可以對(duì)單個(gè)工作負(fù)載(Pod 組)使用垂直和水平縮放。正確的方法是讓 HPA 基于瓶頸資源擴(kuò)展組。VPA 可以控制其他資源。例子:
- CPU綁定的工作負(fù)載可以根據(jù) CPU 利用率水平伸縮,同時(shí)使用垂直伸縮來調(diào)整內(nèi)存。
- IO綁定工作負(fù)載可以基于 IO 吞吐量水平伸縮,同時(shí)使用垂直伸縮來調(diào)整內(nèi)存和 CPU。
然而,這是一種更高級(jí)的自動(dòng)縮放形式,并且 MVP 版本的 Vertical Pod Autoscaler 不能很好地支持它。實(shí)現(xiàn)的難度在于改變實(shí)例數(shù)不僅會(huì)影響瓶頸資源的利用率(這是水平擴(kuò)展的原則),而且可能也會(huì)影響由 VPA 控制的非瓶頸資源。在匯總歷史資源利用率和生成建議時(shí),必須擴(kuò)展 VPA 模型從而能夠?qū)⒔M的大小考慮在內(nèi),以便將其與HPA相結(jié)合。
批量工作負(fù)載
批處理工作負(fù)載具有與延遲敏感工作負(fù)載有不同的 CPU 要求。他們關(guān)心吞吐量而不是請(qǐng)求延遲,這意味著 VPA 應(yīng)該將 CPU 需求基于平均 CPU 消耗而不是高百分位的 CPU 分布。
TODO:描述批處理工作負(fù)載的推薦模型以及VPA如何區(qū)分批處理和服務(wù)。一種可能的方法是查看 PodSpec.restartPolicy。另一種方法是讓用戶在 PodResourcePolicy 中指定工作負(fù)載的延遲要求。