What data formats does the Kubernetes API server support?


When accessing the API server directly (i.e. not with kubectl, but with direct HTTP requests), what formats for the resource specifications does the API server support?

In all examples I have seen so far, the resource specifications are in JSON (for example here). But I couldn't find any general information about this.

Does the API server also accept resource specifications in other formats, such as YAML or protobuf?

Similarly, when the API server returns resources in response to a GET request, are the resources always returned in JSON or are there any other formats supported?

-- weibeld

2 Answers


Managing Kubernetes, Chapter 4 (section "Alternate encodings") says that the API server supports three data formats for resource specifications:

  • JSON
  • YAML
  • Protocol Buffers (protobuf)

I tested creating resources in these formats using curl and it works, as shown in the following.


For easily talking to the API server, start a proxy to the API server with kubectl:

kubectl proxy

Now the API server is accessible on

The Kubernetes API specification is accessible on

Request body formats

You have to specify the format of the HTTP POST request body (i.e. the resource specification) in the Content-Type header.

The following data formats are supported:

  • application/json
  • application/yaml
  • application/vnd.kubernetes.protobuf

Below are concrete examples of requests.

Create a resource with JSON

Define a resource specification in JSON and save it in a file.

For example, pod.json:


Call API server to create the resource:

curl -H "Content-Type: application/json" -d "$(cat pod.json)" -X POST

Create a resource with YAML

Define a resource specification in YAML and save it in a file.

For example, pod.yaml:

apiVersion: v1
kind: Pod
  name: test-pod
  - image: nginx
    name: nginx-container

Call API server to create the resource:

curl -H "Content-Type: application/yaml" -d "$(cat pod.yaml)" -X POST

Create a resource with protobuf

I didn't test this, because the Kubernetes protobuf wire format uses a custom wrapper around the protobuf serialisation of the resource (see here and here). But, in principle, it should work.

Response body formats

When creating a resource as shown above, the API server returns the complete specification of the same resource in the HTTP response (that is, the specification that you submitted, initialised with all the default values, a status field, etc.).

You can choose the format for this response data with the Accept header in the request.

The accepted formats for the Accept header are the same as for the Content-Type header:

  • application/json (default)
  • application/yaml
  • application/vnd.kubernetes.protobuf

For example:

curl -H "Content-Type: application/json" -H "Accept: application/yaml" -d "$(cat pod.json)" -X POST

All combinations of formats in the Content-Type and Accept headers are possible.

-- weibeld
Source: StackOverflow


In Kubernetes both json and YAML formats are supported. am assuming you create and update the resources using kubectl. kubectl accepts both these formats.

if you pass YAML format, Internally the kubectl converts it to json and post it to API server.

-- P Ekambaram
Source: StackOverflow