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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

kubectl create RESOURCE NAME [OPTIONS] [--dry-run=client -o yaml]

Parameters

ParameterDescription
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

Generate a manifest to start from
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-alpine

Run this on your computer — see “Get Started” for setup.

Create a Secret
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.

Was this page helpful?