Open API \u8ba9 API \u63d0\u4f9b\u8005\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u64cd\u4f5c\u548c\u6a21\u578b\uff0c\u5e76\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u81ea\u52a8\u5316\u7684\u751f\u6210\u559c\u6b22\u8bed\u8a00\u7684\u5ba2\u6237\u7aef\uff0c\u7528\u4ee5\u548c API \u670d\u52a1\u5668\u901a\u4fe1\u3002Kubernetes \u5df2\u7ecf\u652f\u6301 Swagger 1.2\uff08OpenAPI \u89c4\u8303\u7684\u524d\u8eab\uff09\u6709\u4e00\u6bb5\u65f6\u95f4\u4e86\uff0c\u4f46\u662f\u8fd9\u4e00\u6807\u51c6\u4e0d\u591f\u5b8c\u6574\u548c\u6709\u6548\uff0c\u51ed\u501f\u8fd9\u4e00\u652f\u6301\uff0c\u975e\u5e38\u96be\u751f\u6210\u5de5\u5177\u6216\u5ba2\u6237\u7aef\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u5728 Kubernetes 1.4\uff0c\u6211\u4eec\u5bf9\u76ee\u524d\u7684\u6a21\u578b\u548c\u64cd\u4f5c\u8fdb\u884c\u4e86\u5347\u7ea7\uff0c\u5f15\u5165\u4e86 Open API \u89c4\u8303\uff08\u5728\u6ca1\u88ab\u6350\u732e\u7ed9 Open API \u4e4b\u524d\u88ab\u79f0\u4f5c Swagger 2.0\uff09\u652f\u6301\u7684 Alpha \u7248\u672c\u3002\u4ece Kubernetes 1.5 \u5f00\u59cb\uff0cOpenAPI \u89c4\u8303\u7684\u652f\u6301\u5df2\u7ecf\u5b8c\u5907\uff0c\u80fd\u591f\u76f4\u63a5\u4ece Kubernetes \u6e90\u7801\u751f\u6210\u89c4\u8303\uff0c\u5bf9\u4e8e\u6a21\u578b\u548c\u65b9\u6cd5\u7684\u4efb\u4f55\u53d8\u66f4\uff0c\u90fd\u4f1a\u4fdd\u969c\u6587\u6863\u548c\u89c4\u8303\u7684\u5b8c\u5168\u540c\u6b65\u3002<\/p>\n
\u65b0\u89c4\u8303\u8ba9\u6211\u4eec\u6709\u4e86\u66f4\u597d\u7684 API \u6587\u6863\uff0c\u751a\u81f3\u8fd8\u6709\u4e86\u4e00\u4e2a Python \u5ba2\u6237\u7aef\u3002<\/p>\n
\u8fd9\u4e00\u6a21\u5757\u5316\u7684\u89c4\u8303\u7528 GroupVersion \u8fdb\u884c\u5206\u9694\uff0c\u8fd9\u4e00\u505a\u6cd5\u5c5e\u4e8e\u672a\u96e8\u7ef8\u7f2a\uff0c\u6211\u4eec\u60f3\u8981\u8ba9\u4e0d\u540c\u7684 API Server \u4f7f\u7528\u4e0d\u540c\u7684 GroupVersion\u3002<\/p>\n
\u89c4\u8303\u7684\u7ed3\u6784\u5728 Open API spec definition \u4e2d\u6709\u89e3\u91ca\u3002\u6211\u4eec\u7528 operation \u6807\u8bb0 \u6765\u62c6\u5206\u6bcf\u4e2a GroupVersion \u5e76\u5c3d\u53ef\u80fd\u7684\u4e30\u5bcc\u5176\u4e2d\u7684\u6a21\u578b\u3001\u8def\u5f84\u3001\u64cd\u4f5c\u7b49\u4fe1\u606f\u3002\u64cd\u4f5c\u7684\u53c2\u6570\u3001\u8c03\u7528\u65b9\u6cd5\u4ee5\u53ca\u54cd\u5e94\u90fd\u6709\u6587\u6863\u63cf\u8ff0\u3002<\/p>\n
\u4f8b\u5982\uff0c\u83b7\u53d6 Pod \u4fe1\u606f\u7684 OpenAPI \u89c4\u8303<\/p>\n
\r\n{\r\n...\r\n \"paths\": {\r\n\"\/api\/v1\/namespaces\/{namespace}\/pods\/{name}\": {\r\n \"get\": {\r\n \"description\": \"read the specified Pod\",\r\n \"consumes\": [\r\n \"*\/*\"\r\n ],\r\n \"produces\": [\r\n \"application\/json\",\r\n \"application\/yaml\",\r\n \"application\/vnd.kubernetes.protobuf\"\r\n ],\r\n \"schemes\": [\r\n \"https\"\r\n ],\r\n \"tags\": [\r\n \"core_v1\"\r\n ],\r\n \"operationId\": \"readCoreV1NamespacedPod\",\r\n \"parameters\": [\r\n {\r\n \"uniqueItems\": true,\r\n \"type\": \"boolean\",\r\n \"description\": \"Should the export be exact. Exact export maintains cluster-specific fields like 'Namespace'.\",\r\n \"name\": \"exact\",\r\n \"in\": \"query\"\r\n },\r\n {\r\n \"uniqueItems\": true,\r\n \"type\": \"boolean\",\r\n \"description\": \"Should this value be exported. Export strips fields that a user can not specify.\",\r\n \"name\": \"export\",\r\n \"in\": \"query\"\r\n }\r\n ],\r\n \"responses\": {\r\n \"200\": {\r\n \"description\": \"OK\",\r\n \"schema\": {\r\n \"$ref\": \"#\/definitions\/v1.Pod\"\r\n }\r\n },\r\n \"401\": {\r\n \"description\": \"Unauthorized\"\r\n }\r\n }\r\n },\r\n\u2026\r\n}\r\n\u2026\r\n<\/pre>\n\u6709\u4e86\u8fd9\u4e9b\u4fe1\u606f\uff0c\u4ee5\u53ca kube-apiserver \u7684 URL\uff0c\u5c31\u53ef\u4ee5\u636e\u6b64\u6765\u8c03\u7528\u63a5\u53e3\u4e86\uff08\/api\/v1\/namespaces\/{namespace}\/pods\/{name}\uff09\uff0c\u53c2\u6570\u5305\u62ec name\u3001exact \u4ee5\u53ca export \u7b49\uff0c\u8c03\u7528\u7ed3\u679c\u4f1a\u8fd4\u56de Pod \u4fe1\u606f\u3002\u5ba2\u6237\u5e93\u751f\u6210\u5668\u4e5f\u4f1a\u4f7f\u7528\u8fd9\u4e9b\u4fe1\u606f\u6765\u521b\u5efa\u4e00\u4e2a API \u51fd\u6570\u8c03\u7528\u6765\u8bfb\u53d6 Pod \u4fe1\u606f\u3002\u4f8b\u5982 Python \u5ba2\u6237\u7aef \u80fd\u591f\u5f88\u7b80\u5355\u7684\u8fdb\u884c\u5982\u4e0b\u8c03\u7528\uff1a<\/p>\n
\r\nfrom kubernetes import client\r\n ret = client.CoreV1Api().read_namespaced_pod(name=\"pods_name\", namespace=\"default\")\r\n https:\/\/gist.github.com\/mbohlool\/d5ec1dace27ef90cf742555c05480146\r\n<\/pre>\n\u4e00\u4e2a\u7b80\u5316\u7248\u7684 read_namespaced_pod;Python Client\uff1ahttps:\/\/github.com\/kubernetes-incubator\/client-python\u8fd8\u53ef\u4ee5\u4f7f\u7528 Swagger-codegen \u6587\u6863\u751f\u6210\u5668\u6765\u6839\u636e\u8fd9\u4e9b\u4fe1\u606f\u751f\u6210\u6587\u6863\uff1a<\/p>\n
\r\nGET \/api\/v1\/namespaces\/{namespace}\/pods\/{name}\r\n (readCoreV1NamespacedPod)\r\n read the specified Pod\r\n Path parameters\r\n name (required)\r\n Path Parameter \u2014 name of the Pod\r\n namespace (required)\r\n Path Parameter \u2014 object name and auth scope, such as for teams and projects\r\n Consumes\r\n This API call consumes the following media types via the Content-Type request header:\r\n *\/*\r\n\r\nQuery parameters\r\n pretty (optional)\r\n Query Parameter \u2014 If 'true', then the output is pretty printed.\r\n exact (optional)\r\n Query Parameter \u2014 Should the export be exact. Exact export maintains cluster-specific fields like 'Namespace'.\r\n export (optional)\r\n Query Parameter \u2014 Should this value be exported. Export strips fields that a user can not specify.\r\n Return type\r\n v1.Pod\r\n\r\nProduces\r\n This 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.\r\n application\/json\r\n application\/yaml\r\n application\/vnd.kubernetes.protobuf\r\n Responses\r\n 200\r\n OK v1.Pod\r\n 401\r\n Unauthorized\r\n<\/pre>\n\u6709\u4e24\u79cd\u65b9\u5f0f\u8bbf\u95ee OpenAPI<\/strong><\/span><\/div>\n\u4ece kube-apiserver\/swagger.json\u3002\u8fd9\u4e2a\u6587\u4ef6\u4f1a\u5305\u542b\u6240\u6709\u542f\u7528\u7684 GroupVersion \u65b9\u6cd5\u548c\u6a21\u578b\uff0c\u5176\u4e2d\u7684\u5185\u5bb9\u4f1a\u662f\u8be5 API Server \u6240\u5bf9\u5e94\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n
Kubernetes \u7684 Github \u4ed3\u5e93\uff0c\u53ef\u4ee5\u8bbf\u95ee master \u6216\u8005\u5176\u4ed6\u6307\u5b9a\u7684 Release\u3002<\/p>\n
\u6709\u5f88\u591a\u5de5\u5177 \u80fd\u548c\u8fd9\u4e9b API \u534f\u540c\u5de5\u4f5c\uff0c\u4f8b\u5982\u53ef\u4ee5\u7528 swagger editor \u6765\u6253\u5f00\u89c4\u8303\u6587\u4ef6\u5e76\u6e32\u67d3\u6587\u6863\uff0c\u6216\u8005\u751f\u6210\u5ba2\u6237\u7aef\uff1b\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5229\u7528 swagger codegen \u6765\u751f\u6210\u6587\u6863\u548c\u5ba2\u6237\u7aef\u3002\u81ea\u52a8\u751f\u6210\u7684\u5ba2\u6237\u7aef\u591a\u6570\u65f6\u5019\u662f\u5f00\u7bb1\u5373\u7528\u7684\u3002\u4e0d\u8fc7\u53ef\u80fd\u9700\u8981\u505a\u4e00\u4e9b\u767b\u5f55\u548c Kubernetes \u76f8\u5173\u7684\u8bbe\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728 Kubernetes 1.4\uff0c\u6211\u4eec\u5bf9\u76ee\u524d\u7684\u6a21\u578b\u548c\u64cd\u4f5c\u8fdb\u884c\u4e86\u5347\u7ea7\uff0c\u5f15\u5165\u4e86 Open API \u89c4\u8303\uff08\u5728\u6ca1\u88ab\u6350\u732e […]<\/p>\n","protected":false},"author":668,"featured_media":142195,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-142192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=142192"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142192\/revisions"}],"predecessor-version":[{"id":142261,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142192\/revisions\/142261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/142195"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=142192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=142192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=142192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}