Operating ReplicaSets
Explore the operating procedure of ReplicaSets to witness its self-healing property in action.
Deleting ReplicaSets
As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with the kubectl delete -f go-demo-2.yml
command.
However, since ReplicaSets and Pods are loosely coupled objects with matching labels, we can remove one without deleting the other.
We can, for example, remove the ReplicaSet we created while leaving the two Pods intact.
kubectl delete -f go-demo-2.yml --cascade=orphan
We use the --cascade=orphan
argument to prevent Kubernetes from removing all the downstream objects. As a result, we get the confirmation "go-demo-2" deleted
.
Let’s confirm it is removed from the system:
kubectl get rs
As expected, the output no resources were found in default namespace.
.
If --cascade=orphan
indeed prevents Kubernetes from removing the downstream objects, the Pods should continue running in the cluster. Let’s confirm the assumption:
kubectl get pods
The output is as follows:
NAME READY STATUS RESTARTS AGEgo-demo-2-md5xp 2/2 Running 0 9mgo-demo-2-vnmf7 2/2 Running 0 9m
The two Pods created by the ReplicaSet are indeed still running in the cluster even though we removed the ReplicaSet.
The Pods that are currently running in the cluster do not have any relation with the ReplicaSet we created earlier. We deleted the ReplicaSet, and the Pods are still there.
Knowing that the ReplicaSet uses labels to decide whether the ...