Which of the following is a valid command to create a PersistentVolume named 'pv-demo' using a YAML manifest file named 'pv.yaml'?
This is the correct and standard declarative command to create or update Kubernetes resources, including PersistentVolumes, from a local or remote YAML manifest. It submits the configuration to the Kubernetes API server, which then provisions or updates the resource state accordingly.
Why this answer
`kubectl apply -f pv.yaml` is the standard Kubernetes command to create or update resources from a YAML manifest file. It reads the manifest, which defines a PersistentVolume named 'pv-demo', and sends it to the API server for creation. This command works for any resource type defined in the file, including PersistentVolumes.
Exam trap
The trap here is that candidates often confuse the `kubectl create` subcommand syntax, thinking that `kubectl create pv` or `kubectl create persistentvolume -f` are valid, when in fact `kubectl apply -f` is the correct and most common way to create resources from a manifest file.
How to eliminate wrong answers
Option A is wrong because `kubectl create pv` is not a valid subcommand; the correct subcommand for creating a PersistentVolume is `kubectl create persistentvolume` (or the short form `pv` is not supported under `create`). Option C is wrong because `kubectl create persistentvolume -f pv.yaml` is syntactically incorrect — the `-f` flag is not used with `kubectl create` for resource-specific subcommands; instead, you must use `kubectl create -f pv.yaml` or `kubectl apply -f pv.yaml`. Option D is wrong because `kubectl run` creates a Pod, not a PersistentVolume; the `--image=pv` flag would attempt to pull a non-existent image, and `--restart=Never` only affects Pod restart policy, not resource type.