Welcome to the Linux Foundation Forum!

5.3 The API Endpoint

sportebois
sportebois Posts: 10
edited January 2017 in LFS258 Class Forum

The snippet from this slide suggests us to ssh the minikube VM then to curl the API.

When I tried this I ran into the issue that minikube VM doesn't come with curl. 

After looking at some docs, I took another approach (and write this here in case other student wonder how to curl the API)

From my host machine, I ran 


kubectl proxy --port=8080 --api-prefix=/

To proxy the api endpoints on my localhost

 

I'm now able to curl the api with 


curl http://localhost:8080/apis | jq

curl http://localhost:8080/api

curl http://localhost:8080/api/va

 

Hope this might save some time to other students with the same issue.

 

Comments

  • sebgoa
    sebgoa Posts: 23
    edited January 2017

    Unfortunately it looks like you are correct.

    The base OS used in minikube changed in v0.15.0 and curl is not available any more.

    I created a bug upstream to get it back: https://github.com/kubernetes/minikube/issues/1059

    In the meantime, I will update the course .

    thanks for reporting this and apologies for the lost time,

    -sebastien

  • Thank you for this!  Out of curiousity, which doc did you find that provided this information?

  • This actually does not seem to work completely for me.  I ran the proxy command and got


    Starting to serve on 127.0.0.1:8080

    which seems to be expected.  Then I opened up another shell and attempted to curl


    <h3>Unauthorized</h3>

    I got the same result when trying to sudo.

  • Figured it out.  I have to hit the endpoints listed above directly.  I couldn't just hit local host on 8080 with specifyin a uri.

  • sebgoa
    sebgoa Posts: 23
    edited February 2017

    Kubernetes developers are putting curl again in the newest version of minikube, so this should not affect folks once there is a new release of minikube.

  • Great news!

    @ryankbales , re your question about the doc... to be honest I don't remember (there are so many docs out there!) I came across this after some googling to try to find out how to make this works ;-) 

  • lalan7
    lalan7 Posts: 1
    edited October 2017

    This is how you can connect to the api with the minikube 0.22.3



     


    <span class="gp" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(85, 85, 85);">$ </span><span class="nv" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(0, 128, 128);">APISERVER</span><span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">=</span><span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">$(</span>kubectl config view | grep server | cut -f 2- -d <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">":"</span> | tr -d <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">" "</span><span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">)</span> <span class="gp" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(85, 85, 85);">$ </span><span class="nv" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(0, 128, 128);">TOKEN</span><span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">=</span><span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">$(</span>kubectl describe secret <span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">$(</span>kubectl get secrets | grep default | cut -f1 -d <span class="s1" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">' '</span><span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">)</span> | grep -E <span class="s1" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">'^token'</span> | cut -f2 -d<span class="s1" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">':'</span> | tr -d <span class="s1" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">'\t'</span><span class="k" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">)</span> <span class="gp" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(85, 85, 85);">$ </span>curl <span class="nv" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(0, 128, 128);">$APISERVER</span>/api --header <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"Authorization: Bearer </span><span class="nv" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(0, 128, 128);">$TOKEN</span><span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"</span> --insecure <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">{</span> <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"kind"</span>: <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"APIVersions"</span>, <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"versions"</span>: <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">[</span> <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"v1"</span> <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">]</span>, <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"serverAddressByClientCIDRs"</span>: <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">[</span> <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">{</span> <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"clientCIDR"</span>: <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"0.0.0.0/0"</span>, <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"serverAddress"</span>: <span class="s2" style="box-sizing: border-box; background: none; margin: 0px; border: 0px; color: rgb(221, 17, 68);">"10.0.1.149:443"</span> <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">}</span> <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">]</span> <span class="o" style="box-sizing: border-box; background: none; margin: 0px; border: 0px;">}</span>
  • sebgoa
    sebgoa Posts: 23
    edited November 2017

    Or you can simply run a proxy `kubectl proxy` and then `curl localhost:8001/api`

  • emanserav
    emanserav Posts: 3
    edited November 2017

    @sebgoa, the course has not been updated yet, not in the PDF, nor in the course itself.

    Indeed if you run a "kubectl proxy" that will start to serve on your machine on 127.0.0.1:8001 and you can then curl as you mentioned above.  

Categories

Upcoming Training