title: How to use raw YAML file inside a curl to create Pod
body: <p>I am trying to create a Pod in Kubernetes using <code>curl</code>.  </p>
  
  <p>This is the YAML:</p>
  
  <pre><code>cat &gt; nginx-pod.yaml &lt;&lt;EOF
  apiVersion: v1
  kind: Pod
  metadata:
    name: nginx1
  spec:
    containers:
    - name: nginx
      image: nginx:1.7.9
      ports:
      - containerPort: 80
  EOF
  </code></pre>
  
  <p>I have token with permissions to do it and I wrote the following <code>curl</code> command:  </p>
  
  <pre><code>curl -k -v -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json;charset=utf-8' https://127.0.0.1:6443/api/v1/namespaces/default/pods --data '{"name":"","namespace":"default","content":"apiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx1\nspec:\n  containers:\n  - name: nginx\n    image: nginx:1.7.9\n    ports:\n    - containerPort: 80\n","validate":true}'
  </code></pre>
  
  <p>Which should be equivalent to the <code>nginx-pod.yaml</code> file.<br>
  The YAML is ok because when I run<code>kubectl create -f nginx.pod.yaml</code> it creates it.<br>
  But when I tried to run it with <code>curl</code> I received:  </p>
  
  <pre><code>&lt; Content-Length: 617
  &lt;
  {
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {
  
    },
    "status": "Failure",
    "message": "Pod \"\" is invalid: [metadata.name: Required value: name or generateName is required, spec.containers: Required value]",
    "reason": "Invalid",
    "details": {
      "kind": "Pod",
      "causes": [
        {
          "reason": "FieldValueRequired",
          "message": "Required value: name or generateName is required",
          "field": "metadata.name"
        },
        {
          "reason": "FieldValueRequired",
          "message": "Required value",
          "field": "spec.containers"
        }
      ]
    },
    "code": 422
  * Connection #0 to host 127.0.0.1 left intact
  </code></pre>
  
  <p>I tried to change the <code>Content-Type</code> to <code>Content-type: text/x-yaml</code> but it didn't help.  </p>
  
  <p>Any idea what can be the reason? </p>
  
  <p>One of the errors is regarding the "metadata.name" field.</p>