You are viewing documentation for Kubernetes version: v1.18

Kubernetes v1.18 documentation is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.

Edit This Page

The Kubernetes API

The Kubernetes API lets you query and manipulate the state of objects in Kubernetes. The core of Kubernetes' control plane is the API server and the HTTP API that it exposes. Users, the different parts of your cluster, and external components all communicate with one another through the API server.

The core of Kubernetes' control planeThe container orchestration layer that exposes the API and interfaces to define, deploy, and manage the lifecycle of containers. is the API serverControl plane component that serves the Kubernetes API. . The API server exposes an HTTP API that lets end users, different parts of your cluster, and external components communicate with one another.

The Kubernetes API lets you query and manipulate the state of objects in the Kubernetes API (for example: Pods, Namespaces, ConfigMaps, and Events).

API endpoints, resource types and samples are described in the API Reference.

API changes

Any system that is successful needs to grow and change as new use cases emerge or existing ones change. Therefore, Kubernetes has design features to allow the Kubernetes API to continuously change and grow. The Kubernetes project aims to not break compatibility with existing clients, and to maintain that compatibility for a length of time so that other projects have an opportunity to adapt.

In general, new API resources and new resource fields can be added often and frequently. Elimination of resources or fields requires following the API deprecation policy.

What constitutes a compatible change, and how to change the API, are detailed in API changes.

OpenAPI specification

Complete API details are documented using OpenAPI.

The Kubernetes API server serves an OpenAPI spec via the /openapi/v2 endpoint. You can request the response format using request headers as follows:

HeaderPossible valuesNotes
Accept-Encodinggzipnot supplying this header is also acceptable
Acceptapplication/com.github.proto-openapi.spec.v2@v1.0+protobufmainly for intra-cluster use
application/jsondefault
*serves application/json
Valid request header values for OpenAPI v2 queries

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.

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/rbac.authorization.k8s.io/v1alpha1.

Versioning is done 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 Kubernetes 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.
  • 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.
  • Stable level:
    • The version name is vX where X is an integer.
    • Stable versions of features will appear in released software for many subsequent versions.

API groups

To make it easier to extend its API, Kubernetes implements API groups. The API group is specified in a REST path and in the apiVersion field of a serialized object.

There are several API groups in a cluster:

  1. The core group, also referred to as the legacy group, is at the REST path /api/v1 and uses apiVersion: v1.

  2. Named groups are at REST path /apis/$GROUP_NAME/$VERSION, and use apiVersion: $GROUP_NAME/$VERSION (e.g. apiVersion: batch/v1). The Kubernetes API reference has a full list of available API groups.

There are two paths to extending the API with custom resources:

  1. CustomResourceDefinition lets you declaratively define how the API server should provide your chosen resource API.
  2. You can also implement your own extension API server 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 as a command line option to the kube-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 API server.

Note: Enabling or disabling groups or resources requires restarting the kube-apiserver and the kube-controller-manager to pick up the --runtime-config changes.

Persistence

Kubernetes stores its serialized state in terms of the API resources by writing them into etcdConsistent and highly-available key value store used as Kubernetes' backing store for all cluster data. .

What's next

Controlling API Access describes how the cluster manages authentication and authorization for API access.

Overall API conventions are described in the API conventions document.

API endpoints, resource types and samples are described in the API Reference.