Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes REST API

Tags:

kubernetes

api

Does kubernetes accessible via a REST API? I was looking over at the Kubernetes API page and it all looks very cryptic / incomplete. They talk about new versions but have not disclosed the API usage or docs anywhere. I just wanted to know if there is a way to access the cluster information in any other way other than using the kubectl command.

Example usage:

What I do now:

kubectl get pod --context='my-prod-cluster'

What I'd like to do:

curl GET /some/parameters/to/get/info

like image 295
Beginner Avatar asked Oct 08 '15 20:10

Beginner


People also ask

Does Kubernetes use REST API?

The REST API is the fundamental fabric of Kubernetes. All operations and communications between components, and external user commands are REST API calls that the API Server handles. Consequently, everything in the Kubernetes platform is treated as an API object and has a corresponding entry in the API.

What are Kubernetes API?

The Kubernetes API is the front end of the Kubernetes control plane and is how users interact with their Kubernetes cluster. The API (application programming interface) server determines if a request is valid and then processes it.

How do I find my Kubernetes API URL?

From inside the pod, kubernetes api server can be accessible directly on "https://kubernetes.default". By default it uses the "default service account" for accessing the api server. So, we also need to pass a "ca cert" and "default service account token" to authenticate with the api server.


2 Answers

You can see all the API calls kubectl is making by passing --v=8 to any kubectl command

like image 124
Jordan Liggitt Avatar answered Oct 15 '22 01:10

Jordan Liggitt


The API is available to you outside of kubectl. In fact, my understanding is that underneath it all kubectl is just making REST calls to the API server. In a cluster using TLS certificates for authentication, a curl call to list your pods might look something like this (you can get your apiserver location/port with kubectl cluster-info | grep 'Kubernetes master'):

curl --cert myuser.pem --key myuser-key.pem --cacert /path/to/ca.pem https://my-prod-cluster-apiserver:6443/api/v1/pods

This doc shows how to use kubectl proxy to allow you to explore the Swagger-generated API docs on your own cluster.

like image 35
rwehner Avatar answered Oct 15 '22 02:10

rwehner