What would happen if we delete the ReplicaSet? As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with a single 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.
What would happen if we delete the ReplicaSet? As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with a single 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.
1
kubectl delete -f go-demo-2.yml --cascade=orphan
Delete Replicasets without deleting pods
We used the --cascade=orphan argument to prevent Kubernetes from removing all the downstream objects. As a result, we got the confirmation that “replicaset go-demo-2” was “deleted”.
Let’s confirm that it is indeed removed from the system.
1
kubectl get rs
Get the List of running Replicasets
As expected, the output states that “no resources were found”.
If --cascade=orphan indeed prevents Kubernetes from removing the downstream objects, the Pods should continue running in the cluster. Let’s confirm the assumption.
1
kubectl get pods
Get the list of running pods
The output is as follows.
123
NAME READY STATUS RESTARTS AGE
go-demo-2-md5xp 2/2 Running 0 9m
go-demo-2-vnmf7 2/2 Running 0 9m
Details of running pods
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 desired number of Pods is already running in the cluster, should lead us to the conclusion that if we create the same ReplicaSet again, it should reuse the two Pods that are running in the cluster. Let’s confirm that.
What would happen if we delete the ReplicaSet? As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with a single 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.
1
kubectl delete -f go-demo-2.yml --cascade=orphan
Delete Replicasets without deleting pods
We used the --cascade=orphan argument to prevent Kubernetes from removing all the downstream objects. As a result, we got the confirmation that “replicaset go-demo-2” was “deleted”.
Let’s confirm that it is indeed removed from the system.
1
kubectl get rs
Get the List of running Replicasets
As expected, the output states that “no resources were found”.
If --cascade=orphan indeed prevents Kubernetes from removing the downstream objects, the Pods should continue running in the cluster. Let’s confirm the assumption.
1
kubectl get pods
Get the list of running pods
The output is as follows.
123
NAME READY STATUS RESTARTS AGE
go-demo-2-md5xp 2/2 Running 0 9m
go-demo-2-vnmf7 2/2 Running 0 9m
Details of running pods
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 desired number of Pods is already running in the cluster, should lead us to the conclusion that if we create the same ReplicaSet again, it should reuse the two Pods that are running in the cluster. Let’s confirm that.
Deleting ReplicaSets
What would happen if we delete the ReplicaSet? As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with a single 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.
1
kubectl delete -f go-demo-2.yml --cascade=orphan
Delete Replicasets without deleting pods
We used the --cascade=orphan argument to prevent Kubernetes from removing all the downstream objects. As a result, we got the confirmation that “replicaset go-demo-2” was “deleted”.
Let’s confirm that it is indeed removed from the system.
1
kubectl get rs
Get the List of running Replicasets
As expected, the output states that “no resources were found”.
If --cascade=orphan indeed prevents Kubernetes from removing the downstream objects, the Pods should continue running in the cluster. Let’s confirm the assumption.
1
kubectl get pods
Get the list of running pods
The output is as follows.
123
NAME READY STATUS RESTARTS AGE
go-demo-2-md5xp 2/2 Running 0 9m
go-demo-2-vnmf7 2/2 Running 0 9m
Details of running pods
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 desired number of Pods is already running in the cluster, should lead us to the conclusion that if we create the same ReplicaSet again, it should reuse the two Pods that are running in the cluster. Let’s confirm that.
What would happen if we delete the ReplicaSet? As you might have guessed, both the ReplicaSet and everything it created (the Pods) would disappear with a single 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.
1
kubectl delete -f go-demo-2.yml --cascade=orphan
Delete Replicasets without deleting pods
We used the --cascade=orphan argument to prevent Kubernetes from removing all the downstream objects. As a result, we got the confirmation that “replicaset go-demo-2” was “deleted”.
Let’s confirm that it is indeed removed from the system.