<p>I am trying to solve how to convert
<code>kubectl create -f file.yaml</code> to <code>curl</code> eqivalent. I have obviously managed to do something like that</p>
<pre><code>curl -ik \ 
-H &quot;Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)&quot; \
https://kubernetes.default.svc.cluster.local/api/v1/namespaces/default/pods
</code></pre>
<p>However, when it comes to <code>curl -X POST ...</code> request, I was not able to figure out how to make <strong>curl</strong> substitute</p>
<pre><code>kubectl create -f file.yaml --v=8
</code></pre>

user2156115
<p>Considering the question of the following post is:</p>
<blockquote>
<p>How can I send a request with <code>curl</code> that will create a resource in Kubernetes cluster with a specified <code>YAML</code> file.</p>
</blockquote>
<p>Dissecting the example from my comment:</p>
<blockquote>
<p>curl -X POST https://kubernetes/api/v1/namespaces/default/pods  -H &quot;Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)&quot; -H &quot;Content-Type: application/yaml&quot; --data-binary @pod.yaml --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt</p>
</blockquote>
<ul>
<li><code>-X POST</code>:
<ul>
<li>send a <code>HTTP</code> request with <code>POST</code> method</li>
</ul>
</li>
<li><code>https://kubernetes/api/v1/namespaces/default/pods</code>:
<ul>
<li>location to send the request to</li>
</ul>
</li>
<li><code>-H &quot;Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)&quot;</code>:
<ul>
<li>set the header with a token for authorization</li>
</ul>
</li>
<li><code>-H &quot;Content-Type: application/yaml&quot;</code>:
<ul>
<li>set the header with a request body type (<code>YAML</code>)</li>
</ul>
</li>
<li><code>--data-binary @pod.yaml</code>:
<ul>
<li>specify the filename that will be send with a request</li>
</ul>
</li>
<li><code>--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt</code>:
<ul>
<li>use the specified certificate file to verify the peer</li>
</ul>
</li>
</ul>
<blockquote>
<p>Disclaimer!</p>
<p>This example assumes that the request comes from a <code>Pod</code> and all of the necessary permissions are assigned to a <code>ServiceAccount</code>.</p>
</blockquote>
<p>Creating different resources like <code>Deployments</code>, <code>Configmaps</code> will require to send the request to a different <code>URL</code> for example:</p>
<ul>
<li><code>Deployment</code>: <code>apis/apps/v1/namespaces/default/deployments</code></li>
<li><code>Configmap</code>: <code>api/v1/namespaces/default/configmaps</code></li>
<li>etc.</li>
</ul>
<blockquote>
<p>A side note!</p>
<p>You will also need to consider the <code>namespace</code> you are sending the request to as sending the resource to the wrong namespace will deny its creation.</p>
</blockquote>
<p>Following command should be helpful on how the <code>curl</code> should look like (path wise):</p>
<ul>
<li><code>kubectl create -f file_name.yaml -v=9</code></li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://curl.se/docs/manpage.html" rel="nofollow noreferrer">Curl.se: Docs: Manpage</a></em></li>
<li><em><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/" rel="nofollow noreferrer">Kubernetes.io: Docs: Reference: Generated: Kubernetes-api: v1.20</a></em></li>
</ul>
