Kubernetes API Tutorial – API Changes & API Versioning

Kuernetes Tutorial – Kubernetes API. The Kubernetes API also serves as the foundation for the declarative configuration schema for the system. Here Coding compiler presenting a tutorial on Kubernetes API. This blog post will give a clear idea about Kubernetes API, let’s start reading now and happy learning.

Kubernetes API

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.

Kubernetes Tutorial – API Changes

In general, 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.

Kubernetes API – OpenAPI and Swagger Definitions

Complete API details are documented using Swagger v1.2 and OpenAPI. The Kubernetes apiserver (aka “master”) exposes an API that can be used to retrieve the Swagger v1.2 Kubernetes API spec located at /swaggerapi. You can also enable a UI to browse the API documentation at /swagger-ui by passing the --enable-swagger-ui=true flag to apiserver.

Starting with Kubernetes 1.4, OpenAPI spec is also available at /swagger.json. While we are transitioning from Swagger v1.2 to OpenAPI (aka Swagger v2.0), some of the tools such as kubectl and swagger-ui are still using v1.2 spec. OpenAPI spec is in Beta as of Kubernetes 1.5.

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.

Kubernetes 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-lifed and/or experimental APIs. The JSON and Protobuf serialization schemas follow the same guidelines for schema changes – all descriptions below cover both formats.

Kubernetes 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:

  1. The core group, often referred to as the legacy group, is at the REST path /api/v1 and uses apiVersion: v1.
  2. The named groups are at REST path /apis/$GROUP_NAME/$VERSION, and use apiVersion: $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:

  1. CustomResourceDefinition is for users with very basic CRUD needs.
  2. Coming soon: 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 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 ex: 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.

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

Enabling resources in the groups

DaemonSets, Deployments, HorizontalPodAutoscalers, Ingress, Jobs and ReplicaSets are enabled by default. Other extensions resources can be enabled by setting --runtime-config on apiserver. --runtime-config accepts comma separated values. For example: to disable deployments and ingress, set --runtime-config=extensions/v1beta1/deployments=false,extensions/v1beta1/ingress=false

Source: Kubernetes Resources

OTHER KUBERNETES TUTORIALS

What is Kubernetes?

Kubernetes Components

Kubernetes Objects

Kubernetes Names And Namespaces

Kubernetes Interview Questions

Want to learn Kubernetes from industry experts?

Get register for a FREE demo on Kubernetes Training @ Contact us.

Leave a Comment