这个rolloutRolling里面包含了所有的秘密,这里我们可以看到。
func (dc *DeploymentController) rolloutRolling(deployment *extensions.Deployment) error { newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(deployment, true) if err != nil { return err } allRSs := append(oldRSs, newRS) // Scale up, if we can. scaledUp, err := dc.reconcileNewReplicaSet(allRSs, newRS, deployment) if err != nil { return err } if scaledUp { // Update DeploymentStatus return dc.updateDeploymentStatus(allRSs, newRS, deployment) } // Scale down, if we can. scaledDown, err := dc.reconcileOldReplicaSets(allRSs, controller.FilterActiveReplicaSets(oldRSs), newRS, deployment) if err != nil { return err } if scaledDown { // Update DeploymentStatus return dc.updateDeploymentStatus(allRSs, newRS, deployment) } dc.cleanupDeployment(oldRSs, deployment) // Sync deployment status return dc.syncDeploymentStatus(allRSs, newRS, deployment) }这里做了如下几件事:
1. 查找新的RS和旧的RS,并计算出新的Revision(这是Revision的最大值);
2. 对新的RS进行扩容操作;
3. 对旧的RS进行缩容操作;
4. 完成之后,删掉旧的RS;
5. 通过Deployment状态到etcd;
至此,我们知道了滚动升级在kubernetes中的原理。其实在传统的负载均衡应用中,滚动升级的做法很类似,但是在容器环境中,我们有RS,通过这种方法更为便捷。
OpenStack, Kubernetes, Mesos 谁主沉浮
在Ubuntu下部署Kubernetes集群