Why doesn't change in .spec.template.metadata.labels for ReplicaSet impact pods

4/28/2016

I have a ReplicaSet defined in a yaml file which was used to create 2 pods (replicas). It is my understanding that changes in the spec section of ReplicaSet will be interpreted as changes in the desired state that will eventually get applied to the real world. For example, PATCHing the number of replicas with:

curl --request PATCH \
     --header 'Content-Type: application/strategic-merge-patch+json' \
     --data '{"spec":{"replicas":3}}' \
     http://localhost:8080/apis/extensions/v1beta1/namespaces/default/replicasets/hello-v2

causes the number of pods to change. However, if I patch the labels to add a label:

 curl --request PATCH \
      --header 'Content-Type: application/strategic-merge-patch+json' \
      --data '{"spec": {"template": {"metadata":{"labels":{"active":"true"}}}}}' \
      http://localhost:8080/apis/extensions/v1beta1/namespaces/default/replicasets/hello-v2

I don't see this change take place on existing pods. New pods (created, for example by scaling the ReplicaSet do contain the new label.

When does a change to a spec impact the current state and when does it not?

-- kalantar
kubernetes

1 Answer

4/28/2016

A change to the Template will only show up when that Template is used to stamp out new replicas. A change outside of the Template (replicas/selector) will be enacted immediately. If you want to gracefully change the PodSpec or labels of already existing Pods, you should take a look at the Rolling Update functionality of Deployments.

-- CJ Cullen
Source: StackOverflow