The Kubernetes APIs
If you want to understand the capabilities of a system and what it provides, you must pay a lot of attention to its API. The API provides a comprehensive view of what you can do with the system as a user. Kubernetes exposes several sets of REST APIs for different purposes and audiences. Some of the APIs are used primarily by tools and some can be used directly by developers. An important aspect of the APIs is that they are under constant development. The Kubernetes developers keep it manageable by trying to extend (adding new objects and new fields to existing objects) and avoid renaming or dropping existing objects and fields. In addition, all API endpoints are versioned, and often have an alpha or beta notation too. For example:
/api/v1 /api/v2alpha1
You can access the API through the kubectl cli
, via client libraries, or directly through REST API calls. There are elaborate authentication and authorization mechanism we will explore in a later chapter. At this point, let's get a glimpse into the surface area of the APIs.
Kubernetes API
This is the main API of Kubernetes. It is huge. All the concepts we discussed before, and many auxiliary concepts, have corresponding API objects and operations. If you have the right permissions you can list, get, create, and update objects. Here is a detailed documentation of one of the most common operations, get a list of all the pods:
GET /api/v1/pods
It accepts various query parameters (all optional):
pretty
: Iftrue
, the output is pretty printedlabelSelector
: A selector expression to limit the resultwatch
: Iftrue
, watch for changes and return a stream of eventsresourceVersion
: Withwatch
, returns only events that occurred after that versiontimeoutSeconds
: Timeout for the list or watch operation
Autoscaling API
The autoscaling API is very focused and lets you control the horizontal pod autoscaler
, which manages a group of pods based on CPU utilization and even application-specific metrics. You can list, query, create, update, and destroy autoscaler
objects using the /apis/autoscaling/v1
endpoint.
Batch API
The batch API lets you manage jobs. Jobs are pods that perform some activity and terminate. Unlike regular pods managed by a replication controller, they are supposed to terminate when the job is done. The batch API uses the pod template to specify jobs and then allows you, as usual, to list, query, create, and delete jobs through the /apis/batch/v1
endpoint.