The Kubernetes API
Overall API conventions are described in the API conventions doc.
API endpoints, resource types and samples are described in API Reference.
Remote access to the API is discussed in the Controlling API Access doc.
The Kubernetes API also serves as the foundation for the declarative configuration schema for the system. The kubectl command-line tool can be used to create, update, delete, and get API objects.
Kubernetes also stores its serialized state (currently in etcd) in terms of the API resources.
Kubernetes itself is decomposed into multiple components, which interact through its API.
- API changes
- OpenAPI and Swagger definitions
- API versioning
- API groups
- Enabling or disabling API groups
- Enabling specific resources in the extensions/v1beta1 group
API changes
In our experience, any system that is successful needs to grow and change as new use cases emerge or existing ones change. Therefore, we expect the Kubernetes API to continuously change and grow. However, we intend to not break compatibility with existing clients, for an extended period of time. In general, new API resources and new resource fields can be expected to be added frequently. Elimination of resources or fields will require following the API deprecation policy.
What constitutes a compatible change and how to change the API are detailed by the API change document.
OpenAPI and Swagger definitions
Complete API details are documented using OpenAPI.
Starting with Kubernetes 1.10, the Kubernetes API server serves an OpenAPI spec via the /openapi/v2
endpoint.
The requested format is specified by setting HTTP headers:
Header | Possible Values |
---|---|
Accept | application/json , application/com.github.proto-openapi.spec.v2@v1.0+protobuf (the default content-type is application/json for */* or not passing this header) |
Accept-Encoding | gzip (not passing this header is acceptable) |
Prior to 1.14, format-separated endpoints (/swagger.json
, /swagger-2.0.0.json
, /swagger-2.0.0.pb-v1
, /swagger-2.0.0.pb-v1.gz
)
serve the OpenAPI spec in different formats. These endpoints are deprecated, and are removed in Kubernetes 1.14.
Examples of getting OpenAPI spec:
Before 1.10 | Starting with Kubernetes 1.10 |
---|---|
GET /swagger.json | GET /openapi/v2 Accept: application/json |
GET /swagger-2.0.0.pb-v1 | GET /openapi/v2 Accept: application/com.github.proto-openapi.spec.v2@v1.0+protobuf |
GET /swagger-2.0.0.pb-v1.gz | GET /openapi/v2 Accept: application/com.github.proto-openapi.spec.v2@v1.0+protobuf Accept-Encoding: gzip |
Kubernetes implements an alternative Protobuf based serialization format for the API that is primarily intended for intra-cluster communication, documented in the design proposal and the IDL files for each schema are located in the Go packages that define the API objects.
Prior to 1.14, the Kubernetes apiserver also exposes an API that can be used to retrieve
the Swagger v1.2 Kubernetes API spec at /swaggerapi
.
This endpoint is deprecated, and was removed in Kubernetes 1.14.
API versioning
To make it easier to eliminate fields or restructure resource representations, Kubernetes supports
multiple API versions, each at a different API path, such as /api/v1
or
/apis/extensions/v1beta1
.
We chose to version at the API level rather than at the resource or field level to ensure that the API presents a clear, consistent view of system resources and behavior, and to enable controlling access to end-of-life and/or experimental APIs. The JSON and Protobuf serialization schemas follow the same guidelines for schema changes - all descriptions below cover both formats.
Note that API versioning and Software versioning are only indirectly related. The API and release versioning proposal describes the relationship between API versioning and software versioning.
Different API versions imply different levels of stability and support. The criteria for each level are described in more detail in the API Changes documentation. They are summarized here:
- Alpha level:
- The version names contain
alpha
(e.g.v1alpha1
). - May be buggy. Enabling the feature may expose bugs. Disabled by default.
- Support for feature may be dropped at any time without notice.
- The API may change in incompatible ways in a later software release without notice.
- Recommended for use only in short-lived testing clusters, due to increased risk of bugs and lack of long-term support.
- The version names contain
- Beta level:
- The version names contain
beta
(e.g.v2beta3
). - Code is well tested. Enabling the feature is considered safe. Enabled by default.
- Support for the overall feature will not be dropped, though details may change.
- The schema and/or semantics of objects may change in incompatible ways in a subsequent beta or stable release. When this happens, we will provide instructions for migrating to the next version. This may require deleting, editing, and re-creating API objects. The editing process may require some thought. This may require downtime for applications that rely on the feature.
- Recommended for only non-business-critical uses because of potential for incompatible changes in subsequent releases. If you have multiple clusters which can be upgraded independently, you may be able to relax this restriction.
- Please do try our beta features and give feedback on them! Once they exit beta, it may not be practical for us to make more changes.
- The version names contain
- Stable level:
- The version name is
vX
whereX
is an integer. - Stable versions of features will appear in released software for many subsequent versions.
- The version name is
API groups
To make it easier to extend the Kubernetes API, we implemented API groups.
The API group is specified in a REST path and in the apiVersion
field of a serialized object.
Currently there are several API groups in use:
The core group, often referred to as the legacy group, is at the REST path
/api/v1
and usesapiVersion: v1
.The named groups are at REST path
/apis/$GROUP_NAME/$VERSION
, and useapiVersion: $GROUP_NAME/$VERSION
(e.g.apiVersion: batch/v1
). Full list of supported API groups can be seen in Kubernetes API reference.
There are two supported paths to extending the API with custom resources:
- CustomResourceDefinition is for users with very basic CRUD needs.
- Users needing the full set of Kubernetes API semantics can implement their own apiserver and use the aggregator to make it seamless for clients.
Enabling or disabling API groups
Certain resources and API groups are enabled by default. They can be enabled or disabled by setting --runtime-config
on apiserver. --runtime-config
accepts comma separated values. For example: to disable batch/v1, set
--runtime-config=batch/v1=false
, to enable batch/v2alpha1, set --runtime-config=batch/v2alpha1
.
The flag accepts comma separated set of key=value pairs describing runtime configuration of the apiserver.
Note: Enabling or disabling groups or resources requires restarting apiserver and controller-manager to pick up the--runtime-config
changes.
Enabling specific resources in the extensions/v1beta1 group
DaemonSets, Deployments, StatefulSet, NetworkPolicies, PodSecurityPolicies and ReplicaSets in the extensions/v1beta1
API group are disabled by default.
For example: to enable deployments and daemonsets, set
--runtime-config=extensions/v1beta1/deployments=true,extensions/v1beta1/daemonsets=true
.
Note: Individual resource enablement/disablement is only supported in theextensions/v1beta1
API group for legacy reasons.
Feedback
Was this page helpful?
Thanks for the feedback. If you have a specific, answerable question about how to use Kubernetes, ask it on Stack Overflow. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.