<p>Using <code>--token</code> flag results in a successful query, but using curl results in a 401.</p>

<pre><code>kubectl --token=eyJhbGciOiJSUzI1NiIsInR... get ns
NAME              STATUS   AGE
default           Active   3m47s
kube-node-lease   Active   3m48s
kube-public       Active   3m48s
kube-system       Active   3m48s
</code></pre>

<pre><code>curl -XGET -H "Authorization: Bearer $TOKEN" -k https://192.168.64.13:8443/apis
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "Unauthorized",
  "reason": "Unauthorized",
  "code": 401
}%
</code></pre>

<p>What is the difference between these two options? My understanding was that they are the same.</p>

<p>My token is a JWT provided by keycloak.</p>

<p><strong>Edit:</strong> More info per responses below...</p>

<p>Running with high verbosity yields a curl request.</p>

<pre><code> k --v=9 --token=$TOKEN get po
I0204 09:10:08.439084   26734 loader.go:375] Config loaded from file:  /Users/me/.kube/config
I0204 09:10:08.445696   26734 round_trippers.go:423] curl -k -v -XGET  -H "Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json" -H "User-Agent: kubectl/v1.17.1 (darwin/amd64) kubernetes/d224476" -H "Authorization: Bearer eyJhbGciOiJSUzI1...." 'https://192.168.64.13:8443/api/v1/namespaces/default/pods?limit=500'
I0204 09:10:08.464046   26734 round_trippers.go:443] GET https://192.168.64.13:8443/api/v1/namespaces/default/pods?limit=500 200 OK in 18 milliseconds
I0204 09:10:08.464070   26734 round_trippers.go:449] Response Headers:
I0204 09:10:08.464074   26734 round_trippers.go:452]     Date: Tue, 04 Feb 2020 17:10:08 GMT
I0204 09:10:08.464078   26734 round_trippers.go:452]     Cache-Control: no-cache, private
I0204 09:10:08.464082   26734 round_trippers.go:452]     Content-Type: application/json
I0204 09:10:08.464086   26734 round_trippers.go:452]     Content-Length: 2931
I0204 09:10:08.464127   26734 request.go:1017] Response Body: {"kind":"Table",..... VALID RESPONSE.
</code></pre>

<p>But <strong><em>Pasting the same curl returns 401</em></strong></p>

<pre><code>curl -k -v -XGET  -H "Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json" -H "User-Agent: kubectl/v1.17.1 (darwin/amd64) kubernetes/d224476" -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cC..." 'https://192.168.64.13:8443/api/v1/namespaces/default/pods?limit=500'

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}
* Connection #0 to host 192.168.64.13 left intact
* Closing connection 0
</code></pre>

<p>How can I perform the same query via curl and get results?</p>

thisguy123
<p>Yes they are same as kubectl internally will do a curl to the API server endpoint.You can view what was the curl request sent to the Kubernetes API Server by running kubectl command with verbosity set and then compare that with the curl command that you are using.</p>

<pre><code>kubectl --v=9 --token=eyJhbGciOiJSUzI1NiIsInR... get ns | grep curl
</code></pre>
