Using Kubectl Create for Manifest Generation: Practical Guidance
kubectl create can generate valid manifests for learning and simple use cases but lacks scalability for complex production needs.
kubectl create can generate valid manifests for learning and simple use cases but lacks scalability for complex production needs.
Workflow for Generating Manifests with kubectl create
- Dry-run resource creation: Use
kubectl create [resource-type] [options] --dry-run=client -o yamlto generate manifests without applying them.
Example:kubectl create deployment pihole --image=pihole/pihole --dry-run=client -o yaml > pihole-deployment.yaml - Output to file: Redirect stdout to a file for reuse:
kubectl create service clusterip --name=homer --port=8080 --target-port=8080 --dry-run=client -o yaml > homer-service.yaml - Validate and adjust: Inspect generated YAML for accuracy, adding labels, selectors, or annotations as needed.
- Apply manifests: Use
kubectl apply -f manifest.yamlto deploy.
Policy Example: When to Use kubectl create
- Allowed for:
- Development/testing environments.
- Simple resources (Services, Deployments, ConfigMaps).
- Quick prototyping or certification exam prep (e.g., CKA).
- Prohibited for:
- Production clusters requiring version control, templating (Helm), or environment-specific overrides (Kustomize).
- Resources needing complex configurations (e.g., StatefulSets with volume claims).
Tooling Complements
- Krew: Extend kubectl with plugins like
k9sfor interactive management orkubectxfor context switching. - kubectl explain: Validate generated manifest fields:
kubectl explain deployment.spec.template.spec.containers - Helm/Kustomize: Use for templating and managing multi-resource stacks (e.g., OwnCloud with persistent volumes and secrets).
Tradeoffs and Caveats
- Pros:
- Fast, built-in, no dependencies.
- Ensures API compatibility (generates valid YAML for current cluster version).
- Cons:
- No version control or drift detection.
- Minimal customization (e.g., can’t easily parameterize image tags).
- Risk of overwriting existing resources if not carefully reviewed.
Troubleshooting Common Issues
- Error: “Invalid option –dry-run”:
Ensure you’re using--dry-run=client(not just--dry-run). - Manifest fails to apply:
Check for missing fields (e.g.,selectorin Services) or invalid API versions (e.g.,apps/v1vsextensions). - Permissions denied:
Run with sufficient context (e.g.,kubectl config use-context dev-cluster). - Generated YAML includes unwanted defaults:
Use--setor manually edit fields (e.g.,resources.requests.memoryin deployments).
For apps like Mealie or Immich, combine kubectl create with manual edits for DB secrets, ingress definitions, or resource limits. Reserve this method for bootstrapping, not long-term maintenance.
Source thread: Is kubectl create a valid way to auto generate valid manifests?

Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Pinterest
Email