/commands/kubernetes/kubectl-create-dry-run-client-yaml
Generate Kubernetes YAML with kubectl create --dry-run=client -o yaml
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Client Version: v1.37.1updated 2026-10-20
- tool
- Kubernetes
- versions
- kubectl 1.18+
- os
- any
kubectl create <kind> ... --dry-run=client -o yaml builds the object on your machine and prints it as YAML instead of sending it to the API server. It is the quickest way to start a manifest with the right apiVersion, labels and selectors; redirect it to a file, edit it, and apply it later.
Deployment, Service, ConfigMap, Secret
kubectl create deployment web --image=nginx:1.29 --replicas=2 --dry-run=client -o yaml
echo ---
kubectl create service clusterip web --tcp=80:8080 --dry-run=client -o yaml
echo ---
kubectl create configmap app --from-literal=MODE=prod --dry-run=client -o yaml
echo ---
kubectl create secret generic db --from-literal=user=admin --dry-run=client -o yamlOutput
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
labels:
app: web
spec:
containers:
- image: nginx:1.29
name: nginx
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
app: web
name: web
spec:
ports:
- name: 80-8080
port: 80
protocol: TCP
targetPort: 8080
selector:
app: web
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: v1
data:
MODE: prod
kind: ConfigMap
metadata:
name: app
---
apiVersion: v1
data:
user: YWRtaW4=
kind: Secret
metadata:
name: dbSecret values are only base64-encoded (YWRtaW4= is admin), not encrypted.
Save, edit, apply
kubectl create deployment web --image=nginx:1.29 --dry-run=client -o yaml > web.yaml
# edit web.yaml: resources, probes, env ...
kubectl apply -f web.yamlWhich kinds can be generated
| Command | Creates |
|---|---|
| kubectl create deployment NAME --image=IMG | Deployment |
| kubectl create service clusterip|nodeport|loadbalancer NAME --tcp=PORT:TARGET | Service |
| kubectl create configmap NAME --from-literal=K=V | --from-file=PATH | ConfigMap |
| kubectl create secret generic NAME --from-literal=K=V | Secret |
| kubectl create job NAME --image=IMG | Job |
| kubectl create cronjob NAME --image=IMG --schedule="*/5 * * * *" | CronJob |
| kubectl create namespace NAME | Namespace |
| kubectl create ingress NAME --rule=host/path=svc:port | Ingress |
Sources
Related pages
cheat sheets · kuberneteskubectl cheat sheet: everyday Kubernetes commandskubectl cheat sheet: contexts and namespaces, get and describe, logs and exec, apply and rollout, port-forward, scaling, and manifests with --dry-run=client.errors · kuberneteskubectl: error converting YAML to JSON: mapping values are not allowed in this contextkubectl apply fails with error converting YAML to JSON: mapping values are not allowed in this context when indentation is wrong or a colon is unquoted.glossary · kubernetesWhat is a Pod in Kubernetes?A Pod is the smallest deployable unit in Kubernetes: one or more containers that share a network namespace, IP address and volumes, always on the same node.