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
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.
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.
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.
You can see all the API calls kubectl is making by passing --v=8
to any kubectl command
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With