Skip to content

/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

bash
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 yaml

Output

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: db

Secret values are only base64-encoded (YWRtaW4= is admin), not encrypted.

Save, edit, apply

bash
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.yaml

Which kinds can be generated

CommandCreates
kubectl create deployment NAME --image=IMGDeployment
kubectl create service clusterip|nodeport|loadbalancer NAME --tcp=PORT:TARGETService
kubectl create configmap NAME --from-literal=K=V | --from-file=PATHConfigMap
kubectl create secret generic NAME --from-literal=K=VSecret
kubectl create job NAME --image=IMGJob
kubectl create cronjob NAME --image=IMG --schedule="*/5 * * * *"CronJob
kubectl create namespace NAMENamespace
kubectl create ingress NAME --rule=host/path=svc:portIngress

Sources