Raghav Gupta:
What is difference between kubectl create -f myfile.yaml and kubectl apply -f myfile.yaml
R Banerjee:
Create allows you to use the file only once.
Apply means you can update any mutable constructs with the same file.
For example, if you want to update a pod, you can do it easily with Apply command, reusing the same command you used to create the pod
Raghav Gupta:
Please correct me if i am wrong i have created deployment with image nginx(say) then in case i have updated the image in yaml file from nginx to busybox then what will impact of kubectl apply command on already running pods?
unnivkn:
if you didn’t change pod name, it will throw error… saying pod already exists, . else you have to use: k replace -f xx.yaml --force
R Banerjee:
From https://kubernetes.io/docs/concepts/workloads/pods/#pod-update-and-replacement
Most of the metadata about a Pod is immutable. For example, you cannot change the namespace, name, uid, or creationTimestamp fields; the generation field is unique. It only accepts updates that increment the field's current value.
If the metadata.deletionTimestamp is set, no new entry can be added to the metadata.finalizers list.
Pod updates may not change fields other than spec.containers[*].image, spec.initContainers[*].image, spec.activeDeadlineSeconds or spec.tolerations. For spec.tolerations, you can only add new entries.
When updating the spec.activeDeadlineSeconds field, two types of updates are allowed:
setting the unassigned field to a positive number;
updating the field from a positive number to a smaller, non-negative number.
1 Like