So far you asked for Pods with flags. A manifest describes the same Pod in a file, and the file can be read, shared, reviewed and applied again.
YAML in three rules
yaml
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27key: value, with a space after the colon.- Indentation is structure. Lines indented under a key belong to it. Use spaces, two per level. Never tabs.
- A dash starts a list item.
containersis a list; each-begins one container, and the lines indented under it belong to that container.
- list itemname: webimage: nginx:1.27same item, same indent
Compare the file with kubectl explain pod.spec --recursive: the YAML follows the schema exactly.
Apply it
Save the file, then send it:
text
learner@shallows:~$ kubectl apply -f web.yaml -n shop
pod/web created-f names the file. -n still picks the namespace, unless the file sets metadata.namespace itself.
Why a file
| With flags | With a file |
|---|---|
kubectl run web --image=nginx:1.27 | kubectl apply -f web.yaml |
| Gone after you press Enter | Stays on disk, can be read and reviewed |
| Only the fields flags can set | Every field the API has |
| Typed again for the next cluster | Applied again, anywhere |
From here on, most things you build are written as files first. The next lesson shows how to get kubectl to write the first draft.