An overview of the
When using K8S related SDK for secondary development, apimachinery, API and client-Go libraries are often used. They are not very clear about their responsibilities, and there is no suitable article on the Internet for analysis. By studying the source code of the three libraries, the author summarizes the dependence between them as follows:
- Apimachinery is the most basic library, including the core data structure, such as Scheme, Group, Version, Kind, Resource, as well as permutations and combinations of commonly used GVK, GV, GK, GVR and so on, as well as encoding, decoding and other operations
- The API library, which relies on Apimachinery, provides built-in k8S resources and an interface to register with Scheme such as Pod, Service, Deployment and Namespace
- The client-go library, which relies on the first two libraries, provides SDKS for accessing k8S built-in resources, the most commonly used being clientSet. The underlying layer accesses the API-server of K8S through HTTP requests to obtain resource information from etCD
Hd address
apimachinery
Apimachinery provides the core data structure of K8S.
Hd address
api
The API library provides k8S built-in resources and interfaces to register with Scheme, such as Pod, Service, Deployment, Namespace
Hd address
client-go
The client-go library is the SDK that accesses k8S built-in resources. The most common one is the clientSet. The underlying layer accesses the API-server of K8S through HTTP requests to obtain resource information from etCD.
For the most important Informer mechanism and principle in client-Go, please refer to my other article: K8S Source Code Analysis – Informer mechanism, which has a detailed source code call diagram.
Hd address
conclusion
- Reading source code is the best way to learn, many materials directly search blogs are not to find the answer, by studying source code can help you build independent thinking ability
- Apimachinery relies more on some tool libraries and will not do analysis here
- The dependencies of the three libraries are in order: Apimachinery -> API -> client-go