Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal: same file, run twice
It worked the first time. The second time, Kubernetes said no. We ran kubectl create on app.yaml, and the deployment web was created. Then we changed replicas from two to three and ran the same command again. The server answered AlreadyExists.
$ kubectl create -f app.yaml
deployment.apps/web created
# edit app.yaml: replicas 2 -> 3
$ kubectl create -f app.yaml
Error from server (AlreadyExists):
deployments.apps "web" already existsSame file, run twice
The difference is intent. Create means make something new, so it refuses when the object already exists. Apply means make the cluster, the running Kubernetes system, match this file. That's why the second apply says configured, with three replicas.
The fix: apply for files you keep editing
With apply, the first run prints created, just like create did. Then you edit replicas from 2 to 3 and run the same command again. This time it prints configured, because apply updates the difference. Use kubectl apply -f for any file you'll keep editing.
$ kubectl apply -f app.yaml
deployment.apps/web created
# edit app.yaml: replicas 2 -> 3
$ kubectl apply -f app.yaml
deployment.apps/web configuredcreate says make it. apply says make it look like this.
Create says make it. Apply says make it look like this. For any file you'll keep editing, default to apply.
