Replicaset-controller why need burstReplicas

1/22/2020

Im studying kubernetes selfhealing function. I want to know meaning of rsc.burstReplicas

func (rsc *ReplicaSetController) manageReplicas(filteredPods []*v1.Pod, rs *apps.ReplicaSet) error {
    diff := len(filteredPods) - int(*(rs.Spec.Replicas))
    rsKey, err := controller.KeyFunc(rs)
    if err != nil {
        utilruntime.HandleError(fmt.Errorf("Couldn't get key for %v %#v: %v", rsc.Kind, rs, err))
        return nil
    }
    if diff < 0 {
        diff *= -1
        if diff > rsc.burstReplicas {
            diff = rsc.burstReplicas
        }
~~~
-- mntky
kubernetes
kubernetes-container

1 Answer

1/22/2020

I am going to guess that that's, actually, the core of kubernetes; current state vs. desired state. And burstReplicas is the amount of replicas it can create or delete at once.

1.- Checking if the current number of pods is above the desired or below:

diff := len(filteredPods) - int(*(rs.Spec.Replicas))

2.- If it is below, it needs to create pods. But first it is going to check if the amount of pods you want to create is above or below the maximum number of pod it can create (500).

if diff < 0 {
    diff *= -1
    if diff > rsc.burstReplicas {          # If you need more then 500 pods,
        diff = rsc.burstReplicas           # it is going to create 500.
    }                                      # Then, will check again

3.- If it is above, it needs to kill pods, but again, it needs to check if the number of pods it needs to kill is above the maximum it can:

} else if diff > 0 {
    if diff > rsc.burstReplicas {
        diff = rsc.burstReplicas
    }
-- suren
Source: StackOverflow