<p>I want to create a secret through kubectl api.
Below is the script, I am running but getting error in parsing yaml file.
Please help</p>

<pre><code>    curl -vk \
    -X POST \
    -d @- \
    -H "Authorization: Bearer $(cat token)" \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    https://ip:port/api/v1/namespaces/nginx-ingress/secrets &lt;&lt;'EOF'
{
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"namespace": "nginx-ingress",
},
"type": "Opaque"
"data": {
"username": "YWRtaW4=",
"password": "MWYyZDFlMmU2N2Rm"
}
EOF
</code></pre>

<p>Error:</p>

<blockquote>
  <p>message": "the object provided is unrecognized (must be of type Secret): couldn't get version/kind; json parse error: invalid character '}' looking for beginning of object key string ({\"apiVersion\": \"v1\",\"kind\": \"S ...)",
    "reason": "BadRequest",</p>
</blockquote>

Sudhir Pandey
<p>I changed my JSON structure in which I added the curly brace which I missed in the end and one comma in the type key.</p>
<pre class="lang-sh prettyprint-override"><code>curl -vk \
    -X POST \
    -d @- \
    -H &quot;Authorization: Bearer $(cat token)&quot; \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    https://192.168.2.100:6443/api/v1/namespaces/nginx-ingress/secrets &lt;&lt;'EOF'
{
 &quot;apiVersion&quot;:&quot;v1&quot;,
 &quot;kind&quot; :&quot;Secret&quot;,
 &quot;metadata&quot; :{&quot;namespace&quot; :&quot;nginx-ingress&quot;,&quot;name&quot;:&quot;mysecret1&quot;},
 &quot;type&quot;: &quot;Opaque&quot;,
 &quot;data&quot;: {&quot;username&quot;: &quot;YWRtaW4=&quot;,&quot;password&quot;: &quot;MWYyZDFlMmU2N2Rm&quot;}
}
</code></pre>
<p>It worked.</p>
