OpenKruise:解放 DaemonSet 运维之路
作者 | 王思宇(酒祝)
前言
背景
apiVersion: apps/v1
kind: DaemonSet
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 2
# ...
apiVersion: apps/v1
kind: DaemonSet
spec:
updateStrategy:
type: OnDelete
# ...
能力解析
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"`
+ // Only when type=SurgingRollingUpdateType, it works.
+ // The maximum number of DaemonSet pods that can be scheduled above the desired number of pods
+ // during the update. Value can be an absolute number (ex: 5) or a percentage of the total number
+ // of DaemonSet pods at the start of the update (ex: 10%). The absolute number is calculated from
+ // the percentage by rounding up. This cannot be 0. The default value is 1. Example: when this is
+ // set to 30%, at most 30% of the total number of nodes that should be running the daemon pod
+ // (i.e. status.desiredNumberScheduled) can have 2 pods running at any given time. The update
+ // starts by starting replacements for at most 30% of those DaemonSet pods. Once the new pods are
+ // available it then stops the existing pods before proceeding onto other DaemonSet pods, thus
+ // ensuring that at most 130% of the desired final number of DaemonSet pods are running at all
+ // times during the update.
+ // +optional
+ MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" protobuf:"bytes,7,opt,name=maxSurge"`
}
type DaemonSetSpec struct {
// ...
+ // BurstReplicas is a rate limiter for booting pods on a lot of pods.
+ // The default value is 250
+ BurstReplicas *intstr.IntOrString `json:"burstReplicas,omitempty" protobuf:"bytes,5,opt,name=burstReplicas"`
}
1. 按节点灰度
apiVersion: apps.kruise.io/v1alpha1
kind: DaemonSet
spec:
# ...
updateStrategy:
type: RollingUpdate
rollingUpdate:
selector:
matchLabels:
nodeType: canary
2. 按数量灰度
apiVersion: apps.kruise.io/v1alpha1
kind: DaemonSet
spec:
# ...
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 100
status.DesiredNumberScheduled - partition
数量的 Pod 滚动升级为新版本。3. 多维度灰度
apiVersion: apps.kruise.io/v1alpha1
kind: DaemonSet
spec:
# ...
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 5
partition: 100
selector:
matchLabels:
nodeType: canary
4. 热升级
apiVersion: apps.kruise.io/v1alpha1
kind: DaemonSet
spec:
# ...
updateStrategy:
rollingUpdate:
type: Surging # defaults to Standard
maxSurge: 30%
type: Surging
,这个类型默认是 Standard -- 也就是先删再扩,而一旦设置为 Surging 则变为先扩再缩。也就是在滚动升级时,DaemonSet 会先在要发布的 Node 上新建一个 Pod,等这个新版本 Pod 变为 ready 之后再把旧版本 Pod 删除掉。5. 发布暂停
apiVersion: apps.kruise.io/v1alpha1
kind: DaemonSet
spec:
# ...
updateStrategy:
rollingUpdate:
paused: true
总结
评论