I created a pod with kubectl create -f pod.xml and kubectl apply -f pod.xml using the below yaml and I don't see any difference, a pod gets created with both the commands. The K8S document, mentions imperative and declarative commands. But, still the create and apply behave the same way.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
What's the difference? Also, how is kubectl apply declarative and kubectl create imperative? Both of them take one or multiple yaml files with the
object details in it.
In plain terms,
createandapplyare essentially the same if you run the operation on a single file to create resources. However,applylets you create and patch at the same time on multiple files under a directory.There's also an
applyto remove resources from a directory but it's in alpha as of this writing:There are more insights on this question too: Kubectl apply vs kubectl create?