kubectl 1.37 reference · Basics
kubectl create Command (kubectl)
Create resources imperatively from the command line: namespaces, deployments, configmaps, secrets, jobs and more.
kubectl 1.37
Syntax
kubectl create RESOURCE NAME [OPTIONS] [--dry-run=client -o yaml]
Parameters
| Parameter | Description |
|---|---|
deployment NAME --image=IMG |
Create a Deployment. |
configmap NAME --from-literal|--from-file |
Create a ConfigMap. |
secret generic NAME --from-literal |
Create a Secret. |
--dry-run=client -o yaml |
Print the manifest instead of creating it. |
Examples
kubectl create deployment web --image=nginx:1.29-alpine --replicas=2 --dry-run=client -o yaml | grep -E '^kind:|replicas:|image:'
Output
kind: Deployment
replicas: 2
- image: nginx:1.29-alpineRun this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-create > /dev/null
trap 'kubectl delete namespace rc-ref-create --wait=false > /dev/null' EXIT
kubectl -n rc-ref-create create secret generic db --from-literal=password=s3cr3t
kubectl -n rc-ref-create get secret db -o jsonpath='{.type}{"\n"}'
Output
secret/db created Opaque
Run this on your computer — see “Get Started” for setup.
Use create ... --dry-run=client -o yaml > file.yaml to scaffold manifests, then manage them with kubectl apply.
Related
kubectl apply· Create or update resources from files, directories or Kustomize folders declaratively; the standard way to deploy manifests.- kubectl Essentials · tutorial