k8s滚动更新算法
k8s rolling update algorithm
我们已经创建了自己的自定义资源 a.k.a CRD,我们需要添加对滚动更新的支持,因为 K8s 支持它用于部署等我们想重用这样的逻辑,有没有我们可以的库使用(也许部分)我们可以用来支持它?或者也许学习并遵循逻辑,因为我们不想重新发明轮子?任何 reference/lib 都会有所帮助。
我好不容易才找到这个 here。
发布社区 wiki 答案以总结问题。
Clark McCauley 好建议:
You're probably looking for the logic contained here.
这是对 k8s 源代码的引用,因此您可能找不到更好的创意来源:)
// rolloutRolling implements the logic for rolling a new replica set.
func (dc *DeploymentController) rolloutRolling(ctx context.Context, d *apps.Deployment, rsList []*apps.ReplicaSet) error {
newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(ctx, d, rsList, true)
if err != nil {
return err
}
allRSs := append(oldRSs, newRS)
// Scale up, if we can.
scaledUp, err := dc.reconcileNewReplicaSet(ctx, allRSs, newRS, d)
if err != nil {
return err
}
if scaledUp {
// Update DeploymentStatus
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}
// Scale down, if we can.
scaledDown, err := dc.reconcileOldReplicaSets(ctx, allRSs, controller.FilterActiveReplicaSets(oldRSs), newRS, d)
if err != nil {
return err
}
if scaledDown {
// Update DeploymentStatus
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}
if deploymentutil.DeploymentComplete(d, &d.Status) {
if err := dc.cleanupDeployment(ctx, oldRSs, d); err != nil {
return err
}
}
// Sync deployment status
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}
我们已经创建了自己的自定义资源 a.k.a CRD,我们需要添加对滚动更新的支持,因为 K8s 支持它用于部署等我们想重用这样的逻辑,有没有我们可以的库使用(也许部分)我们可以用来支持它?或者也许学习并遵循逻辑,因为我们不想重新发明轮子?任何 reference/lib 都会有所帮助。
我好不容易才找到这个 here。
发布社区 wiki 答案以总结问题。
Clark McCauley 好建议:
You're probably looking for the logic contained here.
这是对 k8s 源代码的引用,因此您可能找不到更好的创意来源:)
// rolloutRolling implements the logic for rolling a new replica set.
func (dc *DeploymentController) rolloutRolling(ctx context.Context, d *apps.Deployment, rsList []*apps.ReplicaSet) error {
newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(ctx, d, rsList, true)
if err != nil {
return err
}
allRSs := append(oldRSs, newRS)
// Scale up, if we can.
scaledUp, err := dc.reconcileNewReplicaSet(ctx, allRSs, newRS, d)
if err != nil {
return err
}
if scaledUp {
// Update DeploymentStatus
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}
// Scale down, if we can.
scaledDown, err := dc.reconcileOldReplicaSets(ctx, allRSs, controller.FilterActiveReplicaSets(oldRSs), newRS, d)
if err != nil {
return err
}
if scaledDown {
// Update DeploymentStatus
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}
if deploymentutil.DeploymentComplete(d, &d.Status) {
if err := dc.cleanupDeployment(ctx, oldRSs, d); err != nil {
return err
}
}
// Sync deployment status
return dc.syncRolloutStatus(ctx, allRSs, newRS, d)
}