apply has one promise: after it runs, the cluster matches the file. That makes it safe to run again and again.
Three answers
text
learner@shallows:~$ kubectl apply -f web.yaml -n shop
pod/web created
learner@shallows:~$ kubectl apply -f web.yaml -n shop
pod/web unchanged| apply prints | Meaning |
|---|---|
created | The object did not exist |
configured | It existed and something was changed to match the file |
unchanged | It existed and already matched |
Drift
Someone changes the live object by hand:
text
learner@shallows:~$ kubectl set image pod/web web=nginx:1.26 -n shop
pod/web image updatedThe file still says nginx:1.27. The file and the cluster disagree. That is drift. The next apply ends it:
text
learner@shallows:~$ kubectl apply -f web.yaml -n shop
pod/web configuredThe image is nginx:1.27 again. The hand change is gone.
Remove what a file made
text
learner@shallows:~$ kubectl delete -f web.yaml -n shop
pod "web" deleteddelete -f reads the same file and deletes what it names. Deleting the file from disk does nothing to the cluster.
web.yamledit here
apply -fget -o yaml
Pod webmatches the file