Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access the knative serving api using curl #12410

Closed
jewscojacquez opened this issue Dec 8, 2021 · 6 comments
Closed

How to access the knative serving api using curl #12410

jewscojacquez opened this issue Dec 8, 2021 · 6 comments
Labels
kind/question Further information is requested

Comments

@jewscojacquez
Copy link

Ask your question here:

Hello,

Is there a way that I can list the knative services using REST API call?

For example to list the knative services/routes, I would run kubectl get ksvc or kubectl get route. Is there a way to get this information using curl command from a remote server.

I'm able to get the equivalent call for kubectl get svc with k8s API call - curl -k -H "Authorization: Bearer ${token}" https://masterapi:6443/api/v1/namespaces/{namespace}/service but I just want to list the knative specific services running.

My objective is to list the Knative services on a specific k8s cluster using a browser.

thanks,
Jewsco

@jewscojacquez jewscojacquez added the kind/question Further information is requested label Dec 8, 2021
@nak3
Copy link
Contributor

nak3 commented Dec 9, 2021

I would run kubectl get ksvc or kubectl get route. Is there a way to get this information using curl command from a remote server.

The API for kubectl get ksvc and routes are:

/apis/serving.knative.dev/v1/namespaces/default/services
/apis/serving.knative.dev/v1/namespaces/default/routes

respectively.

We can find these info by using verbose logs. For example:

$ kubectl get ksvc -v 6
I1209 13:56:39.407541 1780052 loader.go:372] Config loaded from file:  /home/knakayam/.kube/config
I1209 13:56:39.419314 1780052 round_trippers.go:454] GET https://127.0.0.1:43377/apis/serving.knative.dev/v1/namespaces/default/services?limit=500 200 OK in 7 milliseconds

It says kubectl get ksvc called https://127.0.0.1:43377/apis/serving.knative.dev/v1/namespaces/default/services.

@jewscojacquez
Copy link
Author

Nak3, you are so impressive! thanks a lot, appreciate your help.

@olokobayusuf
Copy link

Hate to revive a stale issue, but @nak3 can you all add these routes to the documentation, similar to how the official Kubernetes docs provide REST API documentation? There's no mention of the REST API anywhere on the docs, and I've scanned as many docs as you all seem to have.

@nak3
Copy link
Contributor

nak3 commented Mar 12, 2023

Hi @olokobayusuf
Sure, I think we can consider to add the docs. But just FYI, if you have a running k8s cluster with Knative CRD, you can see the openapi like:

$ kubectl proxy --port=8089
$ curl localhost:8089/openapi/v2  > k8s-swagger.json

k8s-swagger.json contains the API raw reference but If you want to see the formatted API reference, you can use swaggerapi image like:

$ docker run \
    --rm \
    -p 80:8080 \
    -e SWAGGER_JSON=/k8s-swagger.json \
    -v $(pwd)/k8s-swagger.json:/k8s-swagger.json \
    swaggerapi/swagger-ui

Then, you can see the API reference on localhost:80 via your browswer like:

image


image

@nak3
Copy link
Contributor

nak3 commented Mar 12, 2023

re-opened knative/docs#3523

@olokobayusuf
Copy link

@nak3 this is an amazing easter egg; I didn't know this existed. I've bookmarked it; thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants