Hello,
In ReplicaSets practice test of CKA course, there was a task to modify the new-replica-set to use correct busybox image. I saved the yaml file of the existing replica set (kubectl get rs new-replica-set -o yaml > new-replica-set.yml). I modified the image name in the yml file and saved it. I then ran command kubectl replace rs -f new-replica-set.yml. However, the pods did not reinitialize. I had to delete the pods or recreate the replica set (delete and create) to fix the issue.
Question: Why did the replace command not reinitialize the pods? How does the replace command update a replica set when it does not reinitialize the pods? What does the replace operation really do, and what does it not do?
It appears that if you try to apply the yaml, it causes an error. Running k delete -f YAML-FILE; k apply -f YAML-FILE
worked, provided you replaced the image in the yaml with a valid name for the busybox image (I used “busybox”).
In this case replace is working a bit like apply.
With replicasets, changing the pod properties does not cause a redeployment of the pods - the RS must be deleted first. That’s one of the issues that Deployment
solves.
You should instead run
kubectl replace --force -f new-replica-set.yml
--force
forces the existing object to be deleted and then recreated. This is also essential when trying to replace a standalone Pod
, otherwise replace would error saying you can’t change properties of a running pod.
Hi Alistair.
In lecture 28 of the CKA course, the slide titled “Scale” should be updated. The k replace command as mentioned in the slide does yields an error without the --force option
The slides are currently all being redesigned for this course. I will ensure the correct command is on the new slide.