Editing nodeSelector doesn't rearrange pods in ReplicaSet

2/6/2018

I have created the following ReplicaSet

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  name: nginx-test
spec:
  replicas: 2
  template:
    metadata:
      name: nginx
      namespace: default
      labels:
        env: beta
    spec:
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
      nodeSelector:
        domain: cloud

This runs the pods in a node marked as cloud. Now I change the nodeSelector using the command

kubectl edit rs/nginx-test

And change the nodeSelector to edge. However the pods are not moved to the edge node. This is working for a Deployment, however not for ReplicaSet. Any ideas

Here are my 2 nodes:

NAME              STATUS    AGE       VERSION   LABELS
x1                 Ready     5d        v1.8.4    beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,domain=cloud,kubernetes.io/hostname=xxxx,node-role.kubernetes.io/master=
x2                 Ready     5d        v1.8.3    beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,domain=edge,kubernetes.io/hostname=xxxx
-- n3o
docker
kubectl
kubernetes
replicaset

1 Answer

2/6/2018

Official Kubernetes documentation recommends that you use a Deployment, which creates ReplicaSets, rather than use ReplicaSets directly.

"A ReplicaSet ensures that a specified number of pod replicas are running at any given time. However, a Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to pods along with a lot of other useful features. Therefore, we recommend using Deployments instead of directly using ReplicaSets, unless you require custom update orchestration or don’t require updates at all."

https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/

It is not unheard of to use a ReplicaSet by itself, but generally not recommended.

If a Deployment works for you, I recommend sticking with that, unless you are using ReplicaSets for some custom thing that Deployments don't work for.

-- Lindsay Landry
Source: StackOverflow