concept kubectl apply in category kubernetes

appears as: kubectl apply
GitOps and Kuberentes

This is an excerpt from Manning's book GitOps and Kuberentes.

: There are two basic ways to deploy Kubernetes: Imperatively using many kubectl commands or declaratively by writing manifests and using kubectl apply. The former is useful for learning and interactive experimentation. The latter is best for reproducible deployments and tracking changes.

We can use the semi-magical kubectl apply command to create the nginx-declarative deployment.

$ kubectl apply -f declarative-deployment.yaml
deployment.apps/nginx-declarative created
$ kubectl get deployments
NAME                READY   UP-TO-DATE   AVAILABLE   AGE
nginx-declarative   3/3     3            3           5m29s
nginx-imperative    3/3     3            3           24m

The kubectl apply command will do a create operation if the nginx-declarative object does not exist or an update if it already exists.

Now, as with the imperative example, what if we want to change the value of the organization annotation from sales to marketing? Let’s edit the declarative-deployment.yaml file. But before we run kubectl apply again, let’s run kubectl diff.