Advanced DaemonSet
控制器基於原生 DaemonSet
上加強了發佈能力,好比 灰度分批、按 Node label
選擇、暫停、熱升級等。html
注意 Advanced DaemonSet
是一個 CRD
,kind
名字也是 DaemonSet
,可是 apiVersion
是 apps.kruise.io/v1alpha1
。這個 CRD
的全部默認字段、默認行爲與原生 StatefulSet
徹底一致,除此以外還提供了一些 optional
字段來擴展加強的策略。node
所以,用戶從原生 DaemonSet
遷移到 Advanced DaemonSet
,只須要把 apiVersion
修改後提交便可:json
- apiVersion: apps/v1 + apiVersion: apps.kruise.io/v1alpha1 kind: DaemonSet metadata: name: sample-ds spec: #...
在 RollingUpdateDaemonSet
中新增瞭如下字段:api
const (+ // StandardRollingUpdateType replace the old daemons by new ones using rolling update i.e replace them on each node one after the other.+ // this is the default type for RollingUpdate.+ StandardRollingUpdateType RollingUpdateType = "Standard"+ // SurgingRollingUpdateType replaces the old daemons by new ones using rolling update i.e replace them on each node one+ // after the other, creating the new pod and then killing the old one.+ SurgingRollingUpdateType RollingUpdateType = "Surging")// Spec to control the desired behavior of daemon set rolling update.type RollingUpdateDaemonSet struct {+ // Type is to specify which kind of rollingUpdate.+ Type RollingUpdateType `json:"rollingUpdateType,omitempty" protobuf:"bytes,1,opt,name=rollingUpdateType"` // ... MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" protobuf:"bytes,2,opt,name=maxUnavailable"`+ // A label query over nodes that are managed by the daemon set RollingUpdate.+ // Must match in order to be controlled.+ // It must match the node's labels.+ Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,opt,name=selector"`+ // The number of DaemonSet pods remained to be old version.+ // Default value is 0.+ // Maximum value is status.DesiredNumberScheduled, which means no pod will be updated.+ // +optional+ Partition *int32 `json:"partition,omitempty" protobuf:"varint,4,opt,name=partition"`+ // Indicates that the daemon set is paused and will not be processed by the+ // daemon set controller.+ // +optional+ Paused *bool `json:"paused,omitempty" protobuf:"varint,5,opt,name=paused"`+ // ...+ MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" protobuf:"bytes,7,opt,name=maxSurge"`}
Advanced DaemonSet
在 spec.updateStrategy.rollingUpdate
中有一個 type
字段,標識瞭如何進行滾動升級:app
Standard:對於每一個 node,控制器會先刪除舊的 daemon Pod,再建立一個新 Pod,和原生 DaemonSet 行爲一致 Surging:對於每一個 node,控制器會先建立一個新 Pod,等它 ready 以後再刪除老 Pod
apiVersion: apps.kruise.io/v1alpha1kind: DaemonSetspec: # ... updateStrategy: type: RollingUpdate rollingUpdate: type: Standard
Selector
標籤選擇升級:這個策略支持用戶經過配置 node
標籤的 selector
,來指定灰度升級某些特定類型 node
上的 Pod
。ide
apiVersion: apps.kruise.io/v1alpha1kind: DaemonSetspec: # ... updateStrategy: type: RollingUpdate rollingUpdate: selector: matchLabels: nodeType: canary
Partition
的語義是 保留舊版本 Pod
的數量,默認爲 0。若是在發佈過程當中設置了 partition
,則控制器只會將 status.DesiredNumberScheduled - partition
數量的 Pod
更新到最新版本。ui
apiVersion: apps.kruise.io/v1alpha1kind: DaemonSetspec: # ... updateStrategy: type: RollingUpdate rollingUpdate: partition: 10
MaxSurge
是 DaemonSet pods
最大擴出來超過預期的數量,只有在 type=SurgingRollingUpdateType
的時候會生效。this
MaxSurge
能夠設置爲絕對值或者一個百分比,控制器針對百分比會基於 status.desiredNumberScheduled
作計算並向上取整,默認值爲 1。code
好比當設置爲 30% 時,最多有總數的 30% 的 node
上會同時有 2 個 Pod
在運行。當新 Pod
變爲 available
以後控制器會下線老 Pod
,而後開始更新下一個 node
,在整個過程當中全部正常 Pod
數量不會超過總 node
數量的 130%。htm
apiVersion: apps.kruise.io/v1alpha1kind: DaemonSetspec: # ... updateStrategy: rollingUpdate: maxSurge: 30%
用戶能夠經過設置 paused
爲 true
暫停發佈,不過控制器仍是會作 replicas
數量管理:
apiVersion: apps.kruise.io/v1alpha1kind: DaemonSetspec: # ... updateStrategy: rollingUpdate: paused: true