Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replicaset doesnot update pods in when pod image is modified

I have created a replicaset with wrong container image with below configuration.

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  name: rs-d33393
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      name: busybox-pod
  template:
    metadata:
      labels:
        name: busybox-pod
    spec:
      containers:
      - command:
        - sh
        - -c
        - echo Hello Kubernetes! && sleep 3600
        image: busyboxXXXXXXX
        name: busybox-container

Pods Information:

$ kubectl get pods
NAME              READY     STATUS             RESTARTS   AGE
rs-d33393-5hnfx   0/1       InvalidImageName   0          11m
rs-d33393-5rt5m   0/1       InvalidImageName   0          11m
rs-d33393-ngw78   0/1       InvalidImageName   0          11m
rs-d33393-vnpdh   0/1       InvalidImageName   0          11m

After this, i try to edit the image inside replicaset using kubectl edit replicasets.extensions rs-d33393 and update image as busybox.

Now, i am expecting pods to be recreated with proper image as part of replicaset.

This has not been the exact result.

Can someone please explain, why it is so?

Thanks :)

like image 999
Sravan Kumar Avatar asked Dec 14 '22 09:12

Sravan Kumar


2 Answers

With ReplicaSets directly you have to kill the old pod, so the new ones will be created with the right image.

If you would be using a Deployment, and you should, changing the image would force the pod to be re-created.

like image 67
suren Avatar answered Dec 15 '22 23:12

suren


Replicaset does not support updates. As long as required number of pods exist matching the selector labels, replicaset's jobs is done. You should use Deployment instead.

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

From the docs:

To update Pods to a new spec in a controlled way, use a Deployment, as ReplicaSets do not support a rolling update directly.

like image 34
Shashank V Avatar answered Dec 15 '22 22:12

Shashank V