Replicaset doesnot update pods in when pod image is modified
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.
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.
Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods. Therefore, it is recommend to use Deployments instead of directly using ReplicaSets unless you don’t require updates at all. ( i.e. one may never need to manipulate ReplicaSet objects when using a Deployment)
Its easy to perform rolling updates and rollbacks when deployed using deployments.
$ kubectl create deployment busybox --image=busyboxxxxxxx --dry-run -o yaml > busybox.yaml$ cat busybox.yamlapiVersion: apps/v1kind: Deploymentmetadata: creationTimestamp: null labels: app: busybox name: busyboxspec: replicas: 1 selector: matchLabels: app: busybox strategy: {} template: metadata: creationTimestamp: null labels: app: busybox spec: containers: - image: busyboxxxxxxx name: busyboxxxxxxx
ubuntu@dlv-k8s-cluster-master:~$ kubectl create -f busybox.yaml --record=truedeployment.apps/busybox created
Check rollout history
ubuntu@dlv-k8s-cluster-master:~$ kubectl rollout history deployment busyboxdeployment.apps/busyboxREVISION CHANGE-CAUSE1 kubectl create --filename=busybox.yaml --record=true
Update image on deployment
ubuntu@dlv-k8s-cluster-master:~$ kubectl set image deployment.app/busybox *=busybox --recorddeployment.apps/busybox image updatedubuntu@dlv-k8s-cluster-master:~$ kubectl rollout history deployment busyboxdeployment.apps/busyboxREVISION CHANGE-CAUSE1 kubectl create --filename=busybox.yaml --record=true2 kubectl set image deployment.app/busybox *=busybox --record=true
Rollback Deployment
ubuntu@dlv-k8s-cluster-master:~$ kubectl rollout undo deployment busyboxdeployment.apps/busybox rolled backubuntu@dlv-k8s-cluster-master:~$ kubectl rollout history deployment busyboxdeployment.apps/busyboxREVISION CHANGE-CAUSE2 kubectl set image deployment.app/busybox *=busybox --record=true3 kubectl create --filename=busybox.yaml --record=true