Protocol Buffers (or protobuf) are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data.
By default, Kubernetes returns objects serialized to JSON with content type application/json
. This is the default serialization format for the API. However, clients may request the Protobuf representation of these objects for better performance at scale.
Stuff you wanna know:
- The Protobuf based serialization format is primarily intended for intra-cluster communication.
- Kubernetes uses an envelope wrapper to encode Protobuf responses. That wrapper starts with a 4 byte number to help identify content in disk or in etcd as Protobuf (as opposed to JSON), and then is followed by a Protobuf encoded wrapper message, which describes the encoding and type of the underlying object and then contains the object.
- Not all API resource types support Protobuf; specifically, Protobuf isn’t available for resources that are defined asCustomResourceDefinitions or are served via the aggregation layer.
- While sending an object in Protobuf to the server for a
PUT
orPOST
call means that you must set theContent-Type
header appropriately. - In Kubernetes, the JSON and Protobuf serialization schemas follow the same guidelines for schema changes.
More stuff:
- Protocol buffers overview — https://developers.google.com/protocol-buffers/docs/overview
- Protobuf Docs — https://developers.google.com/protocol-buffers
- Compiler installation — https://github.com/protocolbuffers/protobuf#protocol-compiler-installation
- Tutorials — https://developers.google.com/protocol-buffers/docs/tutorials
- Kubernetes Protobuf encoding — https://kubernetes.io/docs/reference/using-api/api-concepts/#protobuf-encoding
- Kubernetes Protobuf serialization design proposal (Archived) — https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/protobuf.md
- Moving k8s communication to gRPC — https://blog.cloudflare.com/moving-k8s-communication-to-grpc/