title: How to authenticate against Kubernetes clusters running on Google Container Engine using REST API?
body: <p>I'm writing an application to monitor a kubernetes cluster running on Google Container Engine. On the host where my application deployed, there are no <code>kubectl</code> and <code>gcloud</code> CLI nor are they allowed to be installed. So I am trying to do everything through REST API.</p>
  
  <p>For creating the cluster through REST, I can use <a href="https://cloud.google.com/container-engine/reference/rest/" rel="nofollow noreferrer">GCE Rest API</a> with bearer token retrieved from <a href="https://developers.google.com/oauthplayground/" rel="nofollow noreferrer">Google OAuth Playground</a>. Something like:</p>
  
  <pre><code>curl -i -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Content-Length: 0" -H "Authorization: Bearer $MyBearerToken  https://container.googleapis.com/v1/projects/$PROJECT_ID/zones/$ZONE/serverconfig
  </code></pre>
  
  <p>I can also find <a href="http://kubernetes.io/kubernetes/third_party/swagger-ui/" rel="nofollow noreferrer">Kubernetes REST API reference here</a>. So my question is: <strong>How do I retrieve, say pod information, from my GCE Kubernetes cluster, using REST api and REST api only?</strong></p>
  
  <p>I tried with <code>kubectl get pods --v=8</code>, and it's using <code>GET https://${Kubenetes_IP}/api/v1/namespaces/default/pods</code>. But when I use the same api endpoint to curl with my GCE bearer. It gives me <code>Unzuthorized</code> error message.</p>
  
  <pre><code># curl --insecure -H "Authorization: Bearer $MyBearerToken" https://${Kubenetes_IP}/api/v1/namespaces/default/pods
  Unauthorized
  </code></pre>
  
  <p>I am guessing because I need to use a different bearer token, or some other authentication method. I am wondering if anyone got a quick programtic one-liner? (Without resorting to <code>kubectl</code> or <code>gcloud</code>)</p>
  
  <hr>
  
  <p><strong>Reference</strong></p>
  
  <p><a href="https://stackoverflow.com/a/34598405/3806343">This answer</a> affirms that there <em>is</em> a way using bearer token, but didn't give a pointer or example</p>
  
  <p><a href="https://stackoverflow.com/a/28700532/3806343">This answer</a> also seems promising, but all the link provided are broken (and api are deprecated as well)</p>
  
  <p><a href="http://blog.ctaggart.com/2016/09/accessing-kubernetes-api-on-google.html" rel="nofollow noreferrer">This answer</a> assumes <code>kubectl</code> and <code>gcloud</code> are installed, which is not allowed in my current use case.</p>