kubectl-create
Create Kubernetes resources from file or input
TLDR
Create a resource using the resource definition file
Create a resource from stdin
Create a deployment
Create a deployment with replicas
Create a service
Create a namespace
SYNOPSIS
kubectl create [(-f FILENAME | --filename=FILENAME) | TYPE [NAME] | TYPE NAME FROM FILE FILENAME] [--dry-run=string] [-o output] [--save-config] [--validate] [flags]
PARAMETERS
-f, --filename stringArray
Filenames, directories, or URLs identifying Kubernetes configuration files to create.
--allow-missing-template-keys
Allow missing template keys instead of failing.
--dry-run string
none|server|client: Dry run without creating resources (default: none).
--field-manager string
Name used to track field ownership.
--grace-period int32
Wait time before forcing pod deletion (default: 30s).
--immediate
Bypass graceful deletion and remove immediately.
-k, --kustomize string
Process directory as Kustomization and create resources.
-o, --output string
Output format: json, yaml, name, wide, jsonpath, etc.
--raw
Print the raw unstructured data.
--save-config
Save current config in resource annotation.
--timeout duration
Timeout for operations (e.g., 30s).
--validate
Validate input with schema (default: true).
--v int32[]
Log verbosity levels (deprecated).
--wait
Wait for resources to be created before returning.
DESCRIPTION
kubectl create is a subcommand of kubectl, the command-line interface for Kubernetes, used to imperatively create one or more instances of a resource. It reads resource definitions in YAML or JSON format from files, directories, URLs, or stdin, and submits them to the cluster's API server.
This command is ideal for initial resource provisioning. For example, kubectl create -f deployment.yaml deploys a Kubernetes Deployment defined in the file. It supports common resource types like Pods, Services, Deployments, ConfigMaps, Secrets, Namespaces, and more.
Key features include dry-run modes to preview changes without applying them, validation against schemas, customizable output formats (e.g., YAML, JSON, name), and options for raw output or saving config annotations for future use. It performs server-side validation by default but can be tuned.
Unlike kubectl apply, which is declarative and handles updates via three-way merge patches, create is strictly for creation and fails if the resource exists. It's fast for one-off creations but less suitable for CI/CD pipelines favoring GitOps workflows.
Always ensure proper RBAC permissions on the target namespace. Use --dry-run=server for safe testing in production-like environments.
CAVEATS
Fails if resource already exists; prefer kubectl apply for updates. Requires cluster write permissions. Not suitable for complex overlays without Kustomize.
EXAMPLES
kubectl create deployment nginx --image=nginx
kubectl create -f pod.yaml
kubectl create namespace dev --dry-run=client -o yaml
kubectl create secret generic mysecret --from-literal=key1=value1
RESOURCE TYPES
Supports: deployment, service, pod, configmap, secret, namespace, job, cronjob, ingress, etc. Use kubectl create --help for generators.
HISTORY
Introduced in Kubernetes v1.0 (2014) as core kubectl imperative command. Evolved with features like dry-run (v1.10+), Kustomize support (v1.14+), and validation enhancements. Remains supported but declarative alternatives promoted since v1.18.
SEE ALSO
kubectl apply(1), kubectl delete(1), kubectl get(1), kubectl describe(1), kustomize(1)


