This can be concluded with simple examples:-
Lets create a simple yaml for deploying a pod having image of nginx in it.
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
now we create a pod using kubectl command -
kubectl create -f pod.yaml
Now a pod named nginx is created , you can get info about pods running by -
kubectl get pods -o wide
and detailed view about the pod by
kubectl describe pod nginx
Now if i want to make some changes in my pod.yaml file like this -
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
tier: frontend
title: frontend
spec:
containers:
- name: nginx
image: nginx
now try the command
kubectl create -f pod.yaml
to apply the changes in pod.yaml.
it will have a ouput -
Error from server (AlreadyExists): error when creating "pod.yaml": pods "nginx" already exists
but with the command -
kubectl apply -f pod.yaml
output is -
pod/nginx configured
As in first comment it is very detailed explained that create
like imperative commands are focused on their assigned tasks, you can not assign them further tasks to tweak the world of clusters but apply
like declarative commands are designed to make it work to tweak the world of clusters.