<p>i created user teamcity to be able to use <strong>kube-apiserver</strong> </p>

<blockquote>
  <p>kubectl create serviceaccount teamcity</p>
</blockquote>

<p>With the command below i get  the secrets  name </p>

<blockquote>
  <p>kubectl get accourcissements teamcity -o yaml</p>
</blockquote>

<p>To find the token who were generated by the last command  i use </p>

<blockquote>
  <p>kubectl get secret teamcity-token-lmr6z -o yaml</p>
</blockquote>

<p>when i try to connect by curl i've an error and i dont understand where is my mistake  :( </p>

<pre><code> curl -v -Sskk -H "Authorization: bearer ZXlKaGJH......wWHNIVzZ3" https://10.109.0.88:6443/api/v1/namespaces

 HTTP/1.1 401 Unauthorized
 Content-Type: application/json
 Date: Thu, 05 Jul 2018 13:14:00 GMT
 Content-Length: 165

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "Unauthorized",
  "reason": "Unauthorized",
  "code": 401
* Connection #0 to host 10.109.0.88 left intact
</code></pre>

<p>I found  a small description on kubernetes about why i get this error  (section : Anonymous requests)   <a href="https://kubernetes.io/docs/reference/access-authn-authz/authentication/" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/access-authn-authz/authentication/</a></p>

<p>But i still not understand where is my mistake because with kubectl it's work</p>

<pre><code>kubectl  --token=ZXlKaGJHY2lPaUpTVXpJ........swWHNIVzZ3 get svc
NAME                       TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
hello-kubernetes           NodePort    192.2.0.159   &lt;none&gt;        80:17502/TCP   13d
hello-kubernetes-olivier   NodePort    192.2.0.235   &lt;none&gt;        80:17296/TCP   13d
kubernetes                 ClusterIP   192.2.0.1     &lt;none&gt;        443/TCP        14d 
</code></pre>

morla
<p>It might be your typo the part of "bearer", as i remeber it's "Bearer".</p>

<p>Some command sample is as follows, <a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#directly-accessing-the-rest-api" rel="nofollow noreferrer">Kubernetes - Accessing Clusters</a></p>

<pre><code>$ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")

$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')

$ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "10.0.1.149:443"
    }
  ]
}
</code></pre>
