liveBook · Manning

Kubectl apply

As explained in Kubernetes in Action, Second Edition

kubectl apply is a kubectl command that creates or updates Kubernetes objects from a manifest file or set of manifest files.

kubectl apply creates Kubernetes objects by posting YAML or JSON manifests to the Kubernetes API. It also updates existing objects when you edit the manifest and apply it again. section 5.2.2 section 7.1.2

Create a Pod from a manifest

Run `kubectl apply -f pod.kiada.yaml`. Kubernetes reports `pod "kiada" created`. To update it, edit the manifest and run the same command again. Some Pod fields are immutable; an update can therefore fail, requiring deletion and recreation. section 5.2.2

$ kubectl apply -f pod.kiada.yaml
pod "kiada" created

Shows the minimal command-and-result cycle for creating an object from a manifest. section 5.2.2

Use the same manifest-oriented workflow for larger application definitions:

  • Apply a more complex Pod manifest, then use kubectl get and kubectl describe to confirm that its containers launched. section 5.4.2
  • Apply several files by separating filenames with commas, or apply all supported manifest files in a directory with `kubectl apply -f Chapter05/`. section 5.6.2
  • Include Namespace objects in application manifests when deployment must create the required namespaces as part of the same setup. section 7.1.2
  • Remove file-defined objects with `kubectl delete -f`; use `--recursive` when manifests are stored in subdirectories. section 5.6.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains command usage, repeated updates, multiple-file workflows, directory application, and immutable-field limitations without detailing apply internals.
Examples
Uses Pod manifests, a two-container Envoy Pod, namespace YAML, comma-separated files, and directory application.
What it assumes
Assumes a Kubernetes cluster, kubectl, and a YAML or JSON manifest, while demonstrating manifests and API posting through concrete commands.
What you can do after
Operate/configure Kubernetes applications by creating, updating, grouping, verifying, and removing manifest-defined objects.
How it connects
Connects manifest files with the Kubernetes API, Pods, namespaces, kubectl get, kubectl describe, and kubectl delete.

Also explained in

Compare how 6 books explain kubectl apply →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.