<p>Is it possible to generate yaml with kubernetes kubectl command ? to clarify - I'm not talking about generating yaml from existing deployments like kubectl get XXXX -o yaml, but merely about generating yamls for the very first time for pod, service, ingress, etc. </p>

<p>PS There is a way to get yaml files from kubernetes.io site ( <a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/simple_deployment.yaml" rel="noreferrer">1</a> , <a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/update_deployment.yaml" rel="noreferrer">2</a> ) but I am looking if there is a way to generate yamls templates with kubectl only.</p>

<p>There's the command <code>create</code> in <code>kubectl</code> that does the trick and replaced the <code>run</code> used in the past: let's image you want to create a <em>Deployment</em> running a <em>nginx:latest</em> Docker image.</p>
<pre><code># kubectl create deployment my_deployment --image=busybox --dry-run=client --output=yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: my_deployment
  name: my_deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my_deployment
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: my_deployment
    spec:
      containers:
      - image: busybox
        name: busybox
        resources: {}
status: {}
</code></pre>
<p>Let's analyze each parameter:</p>
<ul>
<li><code>my_deployment</code> is the <em>Deployment</em> name you chose</li>
<li><code>--image</code> is the Docker image you want to deploy</li>
<li><code>--dry-run=client</code> won't execute the resource creation, used mainly for validation.  Replace 'client' with 'true' for older versions of Kubernetes. Neither <code>client</code> nor <code>server</code> will actually create the resource, though <code>server</code> will return an error if the resource cannot be created without a dry run (ie: resource already exists). The difference is very subtle.</li>
<li><code>--output=yaml</code> prints to <em>standard output</em> the YAML definition of the <em>Deployment</em> resource.</li>
</ul>
<p>Obviously, you can perform this options just with few Kubernetes default resources:</p>
<pre><code># kubectl create 
  clusterrole         Create a ClusterRole.
  clusterrolebinding  Create a ClusterRoleBinding for a particular ClusterRole
  configmap           Create a configmap from a local file, directory or literal value
  deployment          Create a deployment with the specified name.
  job                 Create a job with the specified name.
  namespace           Create a namespace with the specified name
  poddisruptionbudget Create a pod disruption budget with the specified name.
  priorityclass       Create a priorityclass with the specified name.
  quota               Create a quota with the specified name.
  role                Create a role with single rule.
  rolebinding         Create a RoleBinding for a particular Role or ClusterRole
  secret              Create a secret using specified subcommand
  service             Create a service using specified subcommand.
  serviceaccount      Create a service account with the specified name
</code></pre>
<p>According to this, you can render the template without the prior need of deploying your resource.</p>
