Kubernetes: Create, generate & apply YAML
10 Kubernetes commands: Create, generate & apply YAML. Click a command to see what each part does.
Kubernetes: Create, generate & apply YAMLIndex
- Whole sheet137
- Basics: cluster, namespaces & resources17
- Get & list resources23
- Context & namespace3
- Find resources9
- Debug: describe, events, logs8
- Exec, port-forward, copy4
- Deploy, roll out, roll back, scale7
- Cleanup & nodes4
- Services, DNS & networking checks6
- Environment, config & secrets of workloads9
- Create, generate & apply YAML10
- Patch, label, annotate & scale9
- Delete & force delete6
- Nodes, scheduling & access control11
- Productivity: aliases, contexts & output11
Create, generate & apply YAML10
kubectl run <name> --image=<image> --port=<port> --dry-run=client -o yaml > pod.yamlGenerate a pod manifestWhat each part does
kubectl run <name> --image=<image>a single pod (the old --generator flag is gone)--dry-run=client -o yamlprint YAML instead of creating> pod.yamlsave to edit
kubectl expose deploy <deployment> --port=<port> --target-port=<container-port> --dry-run=client -o yaml > svc.yamlGenerate a service manifestWhat each part does
expose deploy <deployment>service selecting the deployment's pods--port / --target-portservice port / container port--dry-run=client -o yamlYAML only
kubectl create job <job-name> --from=cronjob/<cronjob> -n <namespace>Create a job from a cronjob (run it now)What each part does
create job --from=cronjob/<cronjob>one-off Job using the CronJob's template-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl create cronjob <name> --image=<image> --schedule='*/5 * * * *' -- <command>Create a cronjobWhat each part does
--schedule='...'cron schedule-- <command>what the container runs
kubectl get deploy <deployment> -n <namespace> -o yaml > deploy.yamlExport an existing object as clean YAMLWhat each part does
-o yamlthe full object; remove status, metadata.uid, resourceVersion, managedFields before re-applying (--export no longer exists; the kubectl-neat plugin strips them)
kubectl apply -R -f <dir>Apply a directory recursivelyWhat each part does
-Rrecurse into subdirectories-f <dir>every manifest in it
kubectl apply -k <overlay-dir>Apply a Kustomize overlayWhat each part does
-k <dir>render kustomization.yaml and apply; kubectl kustomize <dir> just prints it
kubectl apply --server-side -f <file>Server-side applyWhat each part does
--server-sidethe API server merges and tracks field ownership; needed for large CRDs
kubectl replace --force -f <file>Replace an object (delete + recreate)CautionWhat each part does
replace --forcedelete and recreate: for fields that can't be changed in place
kubectl wait --for=condition=Ready pod -l app=<app> --timeout=120s -n <namespace>Wait until pods are readyWhat each part does
kubectl wait --for=condition=Readyblock until the condition is true (also --for=delete, --for=jsonpath=...)pod -l app=<app>which objects--timeout=120sfail after 2 minutes
Nothing matches.
My DevOps Playbook by Angelo John Calleja