Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the new function of OpenAPI

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what is the new function of OpenAPI", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the new feature of OpenAPI" can help you solve your doubts.

Open API is open API, also known as open platform. The so-called open API (OpenAPI) is a common application of service-oriented websites. Website service providers encapsulate their website services into a series of API (open for third-party developers to use). This behavior is called open website API, and the open API is called OpenAPI (open API).

In Kubernetes 1.4, we upgraded the current model and operation to introduce a version of Alpha supported by the Open API specification (called Swagger 2.0 before it was donated to Open API). Starting with Kubernetes 1.5, the OpenAPI specification has been fully supported and can be generated directly from the Kubernetes source code, ensuring full synchronization of documents and specifications for any changes to the model and method.

The new specification gives us better API documentation and even a Python client.

This modular specification is separated by GroupVersion, which is prepared in advance, and we want different API Server to use different GroupVersion.

The structure of the specification is explained in Open API spec definition. We use operation tags to split each GroupVersion and enrich the model, path, operation and other information as much as possible. The parameters of the operation, the calling method, and the response are all documented.

For example, the OpenAPI specification for obtaining Pod information

{... "paths": {"/ api/v1/namespaces/ {namespace} / pods/ {name}": {"get": {"description": "read the specified Pod", "consumes": ["* / *"], "produces": ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"], "schemes": ["https"] "tags": [core_v1 "]," operationId ":" readCoreV1NamespacedPod "," parameters ": [{" uniqueItems ": true," type ":" boolean "," description ":" Should the export be exact. Exact export maintains cluster-specific fields like 'Namespace'. "," name ":" exact "," in ":" query "}, {" uniqueItems ": true," type ":" boolean "," description ":" Should this value be exported. Export strips fields that a user can not specify. "," name ":" export "," in ":" query "}]," responses ": {" description ":" OK "," schema ": {" $ref ":" # / definitions/v1.Pod "}} {"description": "Unauthorized"}}, … }...

With this information, as well as the URL of kube-apiserver, you can call the interface (/ api/v1/namespaces/ {namespace} / pods/ {name}). The parameters include name, exact, export, and so on. The result of the call will return Pod information. The client library generator also uses this information to create an API function call to read the Pod information. For example, the Python client can simply make the following calls:

From kubernetes import clientret = client.CoreV1Api () .read_namespaced_pod (name= "pods_name", namespace= "default") https://gist.github.com/mbohlool/d5ec1dace27ef90cf742555c05480146

A simplified version of read_namespaced_pod;Python Client: https://github.com/kubernetes-incubator/client-python can also use the Swagger-codegen document generator to generate documents based on this information:

GET / api/v1/namespaces/ {namespace} / pods/ {name} (readCoreV1NamespacedPod) read the specified PodPath parametersname (required) Path Parameter-name of the Podnamespace (required) Path Parameter-object name and auth scope, such as for teams and projectsConsumesThis API call consumes the following media types via the Content-Type request header:*/*Query parameterspretty (optional) Query Parameter-If 'true', then the output is pretty printed.exact (optional) Query Parameter-Should the export be exact. Exact export maintains cluster-specific fields like 'Namespace'.export (optional) Query Parameter-Should this value be exported. Export strips fields that a user can not specify.Return typev1.PodProducesThis API call produces the following media types according to the Accept request header; the media type will be conveyed by the Content-Type response header.application/jsonapplication/yamlapplication/vnd.kubernetes.protobufResponses200OK v1.Pod401Unauthorized

There are two ways to access OpenAPI

From kube-apiserver/swagger.json. This file will contain all enabled GroupVersion methods and models, and the contents will be the latest version of the API Server.

Kubernetes's Github repository, which can access master or other specified Release.

There are many tools that can work with these API, such as using swagger editor to open specification files and render documents, or to generate clients; you can also directly use swagger codegen to generate documents and clients. Automatically generated clients are used out of the box most of the time. However, you may need to make some login and Kubernetes-related settings.

After reading this, the article "what are the new functions of OpenAPI" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report