k8s滚动更新算法



我们已经创建了自己的自定义资源,也称为CRD,我们需要添加对滚动更新的支持,因为K8s支持它进行部署等。我们想重用这样的逻辑,有没有我们可以使用(可能是部分(的库可以用来支持它?或者学习并遵循逻辑,因为我们不想重新发明轮子?任何引用/lib都会有所帮助。

我很难在这里找到这个。

发布社区wiki答案以总结问题。

Clark McCauley建议:

您可能正在查找此处包含的逻辑。

这是对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)
}

最新更新