<p>Practicing with Kubernetes.</p>

<p>Is it possible to create a <code>YAML</code> deployment object and its configuration through <code>Bash</code> only? </p>

<p>I have tried this:</p>

<pre><code>kubectl create -f deployment.yaml
</code></pre>

<p>to create a yaml so i could edit later. However it just displays </p>

<pre><code>error: the path "deployment.yaml" does not exist
</code></pre>

dude Funk1
<p>All the answers so far advocate actually deploying to the cluster, then retrieving the running deployment. </p>

<p>Using the <code>--dry-run</code> you can get the YAML format of the object without actually deploying anything. For example:</p>

<pre><code>kubectl create deployment nginx --image=nginx --dry-run -o yaml
</code></pre>

<p>Will output the deployment YAML to stdout:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
</code></pre>
