What I understood by the documentation is that kubectl apply = kubectl create + kubectl replace. Reference
My understanding is that
if I want create new k8s resource in the cluster I should use kubectl create operation. Now If I want to update something in a live k8s resources I should use kubectl replace operation.
If I want to do both operations (create a new k8s resource as well as update the live k8s resources ) then I should use kubectl apply operation
My questions are Why are there three operations for doing the same task in a cluster? What are the use cases for these operations? How do they differ from each other under the hood?
At the moment I am using kubectl create operation for creating new resources in the cluster. Thanks
Those are two different approaches.
kubectl create is what we call Imperative Management. On this approach you tell the Kubernetes API what you want to create, replace or delete, not how you want your K8s cluster world to look like.
kubectl apply is part of the Declarative Management approach, where changes that you may have applied to a live object (i.e. through
scale) are maintained even if you
apply other changes to the object.
You can read more about imperative and declarative management in the Kubernetes Object Management documentation.