When to use kubectl create or kubectl apply

Prabhakar Lal:
when to use kubectl create or kubectl apply

Oliver Radwell:
apply is usually when you have a yaml file. create is when you don’t. using create you can also output to file: kubectl create deployment my-deployment --replicas=1 --image=nginx --dry-run=client -oyaml > my-deployment.yaml
then you can use kubectl apply -f my-deployment.yaml to create / update it

Prabhakar Lal:
any more differences

Fernando Jimenez:
kubectl create is an imperative command and the difference will be between an object and another object. kubectl apply -f is declarative, the content of the file is the desired state.

Sidd:
@Fernando Jimenez and when do you use kubectl run ?

Fernando Jimenez:
If you want to imperatively spin up a pod object you use kubectl run <pod-name> --image=<image-name>
If instead, you want to not immediately spin up the pod but rather create a template to further modify before spinning up the pod, you can do it as well with

kubectl run <pod-name> --image=<image-name> --dry-run=client -o yaml > pod.yaml

Sidd:
If I understand corrent I can use either kubectl run or kubectl create