摘要:它實現(xiàn)了中的橫向自動擴容。目前只支持針對使用度進行動態(tài)擴容。這個就是真正控制擴容的,其結(jié)構(gòu)如下其中的是一個的引用,定義了自動擴容的配置允許的最大實例數(shù),最小實例數(shù),以及使用配額。這也是為了避免出現(xiàn)頻繁的擴容縮容。
最新一版的kubernetes release中我們看到了一個令人欣喜的特性:Autoscaling。它實現(xiàn)了replicationcontroller中pod的橫向自動擴容。以下是摘自官方文檔的相關(guān)內(nèi)容:
自動擴容將通過一個新的resource(就像之前的pod,service等等)實現(xiàn)。目前只支持針對cpu使用度進行動態(tài)擴容。未來的版本中,將會實現(xiàn)基于另一個resource:metrics(這是說未來監(jiān)控數(shù)據(jù)將會有一個更統(tǒng)一的展示?)
主要結(jié)構(gòu)1.Scale subresource
Scale subresource是一個虛擬的resource,用來記錄擴容進度。其主要結(jié)構(gòu)如下:
// represents a scaling request for a resource. type Scale struct { unversioned.TypeMeta api.ObjectMeta // defines the behavior of the scale. Spec ScaleSpec // current status of the scale. Status ScaleStatus } // describes the attributes of a scale subresource type ScaleSpec struct { // desired number of instances for the scaled object. Replicas int `json:"replicas,omitempty"` } // represents the current status of a scale subresource. type ScaleStatus struct { // actual number of observed instances of the scaled object. Replicas int `json:"replicas"` // label query over pods that should match the replicas count. Selector map[string]string `json:"selector,omitempty"` }
其中ScaleSpec.Replicas表示我們預(yù)定的集群實例數(shù)目標(biāo)。ScaleStatus.Replicas表示當(dāng)前實例數(shù),ScaleStatus.Selector是一個選擇器,選擇對應(yīng)的pods。
2.HorizontalPodAutoscaler
這個就是真正控制擴容的resource,其結(jié)構(gòu)如下:
// configuration of a horizontal pod autoscaler. type HorizontalPodAutoscaler struct { unversioned.TypeMeta api.ObjectMeta // behavior of autoscaler. Spec HorizontalPodAutoscalerSpec // current information about the autoscaler. Status HorizontalPodAutoscalerStatus } // specification of a horizontal pod autoscaler. type HorizontalPodAutoscalerSpec struct { // reference to Scale subresource; horizontal pod autoscaler will learn the current resource // consumption from its status,and will set the desired number of pods by modifying its spec. ScaleRef SubresourceReference // lower limit for the number of pods that can be set by the autoscaler, default 1. MinReplicas *int // upper limit for the number of pods that can be set by the autoscaler. // It cannot be smaller than MinReplicas. MaxReplicas int // target average CPU utilization (represented as a percentage of requested CPU) over all the pods; // if not specified it defaults to the target CPU utilization at 80% of the requested resources. CPUUtilization *CPUTargetUtilization } type CPUTargetUtilization struct { // fraction of the requested CPU that should be utilized/used, // e.g. 70 means that 70% of the requested CPU should be in use. TargetPercentage int } // current status of a horizontal pod autoscaler type HorizontalPodAutoscalerStatus struct { // most recent generation observed by this autoscaler. ObservedGeneration *int64 // last time the HorizontalPodAutoscaler scaled the number of pods; // used by the autoscaler to control how often the number of pods is changed. LastScaleTime *unversioned.Time // current number of replicas of pods managed by this autoscaler. CurrentReplicas int // desired number of replicas of pods managed by this autoscaler. DesiredReplicas int // current average CPU utilization over all pods, represented as a percentage of requested CPU, // e.g. 70 means that an average pod is using now 70% of its requested CPU. CurrentCPUUtilizationPercentage *int }
其中的ScaleRef是一個Scale subresource的引用,MinReplicas, MaxReplicas and CPUUtilization定義了自動擴容的配置(允許的最大實例數(shù),最小實例數(shù),以及cpu使用配額)。
3.HorizontalPodAutoscalerList
用于記錄一個namespace下的所有HorizontalPodAutoscaler。本質(zhì)上是一個結(jié)構(gòu)數(shù)組。
官方文檔給出的并不是算法, 而是實現(xiàn)步驟,整個自動擴容的流程是:
1.通過podselector找到要擴容的集群
2.收集集群最近的cpu使用情況(CPU utilization)
3.對比在擴容條件里記錄的cpu限額(CPUUtilization)
4.調(diào)整實例數(shù)(必須要滿足不超過最大/最小實例數(shù))
5.每隔30s做一次自動擴容的判斷(這個日后應(yīng)該會成為一個擴容條件的參數(shù))
CPU utilization的計算方法是用cpu usage(最近一分鐘的平均值,通過heapster可以直接獲取到)除以cpu request(這里cpu request就是我們在創(chuàng)建容器時制定的cpu使用核心數(shù))得到一個平均值,這個平均值可以理解為:平均每個CPU核心的使用占比。未來k8s會開放一個api直接獲取heapster收集到的監(jiān)控數(shù)據(jù)。
真正的算法是:
A.
TargetNumOfPods = ceil(sum(CurrentPodsCPUUtilization) / Target)
ceil()表示取大于或等于某數(shù)的最近一個整數(shù)
舉個栗子:
我們有一個集群實例數(shù)是3 pods。cpu限額,即Target是每個pod分配1.1核,當(dāng)cpu的使用度CurrentPodsCPUUtilization為1.1,1.4,1.3時,要擴容成多少個呢?
ceil((1.1+1.4+1.3)/1.1)= 4
所以擴容成四個實例。
B.
由于啟動實例時cpu的使用度會陡增,所以自動擴容會等待一段時間以收集準(zhǔn)確的運行時監(jiān)控數(shù)據(jù)。每次擴容/縮容后冷卻三分鐘才能再度進行擴容,而縮容則要等5分鐘后。這是因為自動擴容使用保守的方法,盡可能滿足pods業(yè)務(wù)的正常使用,所以擴容的優(yōu)先級要大于縮容。
C.
當(dāng)滿足:
avg(CurrentPodsConsumption) / Target >1.1 或 <0.9
時才會觸發(fā)進行擴容/縮容。這也是為了避免出現(xiàn)頻繁的擴容縮容。
為了方便使用,建議采用相對(relative)的度量標(biāo)準(zhǔn)(如 90%的cpu資源)而不是絕對的標(biāo)準(zhǔn)(如0.6個cpu核心)來描述擴容條件。否則,當(dāng)用戶修改pods的請求資源時還需要去修改這些絕對值。比如:我們創(chuàng)建一個集群時,podtemplate中的resource里填入了cpu為1,即最多分配一個cpu核心給該pod,如果在擴容條件中采用絕對標(biāo)準(zhǔn),我們必須填一個小于1的數(shù),否則這個條件根本不會被觸發(fā)。而當(dāng)我們要修改分配的資源為0.8個核心時,又必須要修改擴容條件以確保其小于0.8。這就很麻煩了。
kubectl中的支持以及待支持為了方便使用,在kubectl的cmd命令中加入了 creating/updating/deleting/listing 命令用來操作HorizontalPodAutoscaler
未來可能會加入像kubectl autoscale這樣的命令,對一個已經(jīng)在跑的集群實時進行動態(tài)擴容。
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/32423.html
摘要:月日,首期沙龍海量運維實踐大曝光在騰訊大廈圓滿舉行??椩聘咝У膶嵺`是,它是以運維標(biāo)準(zhǔn)化為基石,以為核心的自動化運維平臺。 作者丨周小軍,騰訊SNG資深運維工程師,負責(zé)社交產(chǎn)品分布式存儲的運維及團隊管理工作。對互聯(lián)網(wǎng)網(wǎng)站架構(gòu)、數(shù)據(jù)中心、云計算及自動化運維等領(lǐng)域有深入研究和理解。 12月16日,首期沙龍海量運維實踐大曝光在騰訊大廈圓滿舉行。沙龍出品人騰訊運維技術(shù)總監(jiān)、復(fù)旦大學(xué)客座講師、De...
摘要:彈性伸縮是指在業(yè)務(wù)需求增長時自動增加計算資源虛擬機以保證計算能力,在業(yè)務(wù)需求下降時自動減少計算資源以節(jié)省成本同時可結(jié)合負載均衡及健康檢查機制,滿足請求量波動和業(yè)務(wù)量穩(wěn)定的場景。彈性伸縮(Auto Scaling)是指在業(yè)務(wù)需求增長時自動增加計算資源(虛擬機)以保證計算能力,在業(yè)務(wù)需求下降時自動減少計算資源以節(jié)省成本;同時可結(jié)合負載均衡及健康檢查機制,滿足請求量波動和業(yè)務(wù)量穩(wěn)定的場景。用戶可通...
摘要:全面支持后端服務(wù)的高可用調(diào)整優(yōu)化后端服務(wù)組件個中等級別以上的修復(fù)云幫社區(qū)版迎來了年月升級版本,我們優(yōu)化了云幫的安裝部署流程,全面支持后端服務(wù)的高可用,改進了相關(guān)提示信息文案,完善了平臺日志模塊,升級了部分核心組件版本。 全面支持后端服務(wù)的高可用、調(diào)整優(yōu)化后端服務(wù)組件、4個中等級別以上的bug修復(fù)、云幫社區(qū)版迎來了2017年5月升級版本,我們優(yōu)化了云幫的安裝部署流程,全面支持后端服務(wù)的高...
摘要:本文中,我們將描述系統(tǒng)的架構(gòu)開發(fā)演進過程,以及背后的驅(qū)動原因。應(yīng)用管理層提供基本的部署和路由,包括自愈能力彈性擴容服務(wù)發(fā)現(xiàn)負載均衡和流量路由。 帶你了解Kubernetes架構(gòu)的設(shè)計意圖、Kubernetes系統(tǒng)的架構(gòu)開發(fā)演進過程,以及背后的驅(qū)動原因。 showImg(https://segmentfault.com/img/remote/1460000016446636?w=1280...
閱讀 1588·2021-09-24 10:38
閱讀 1524·2021-09-22 15:15
閱讀 3074·2021-09-09 09:33
閱讀 913·2019-08-30 11:08
閱讀 650·2019-08-30 10:52
閱讀 1263·2019-08-30 10:52
閱讀 2358·2019-08-28 18:01
閱讀 533·2019-08-28 17:55