方便的 Kubernetes API 参考文档

Posted isea533

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了方便的 Kubernetes API 参考文档相关的知识,希望对你有一定的参考价值。

https://k8s.mybatis.io

关注过 K8s 的人可能都看过官方的 API 参考文档:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13

这个文档的形式如下图所示:

如果你真正参考过这个文档,你会发现这个文档特别不好用,想要逐级查看属性信息时,经常在锚点之间跳转,无法从整体上看到完整的结构,非常难用!!!

为了方便使用这个文档,我提取了整个文档的结构化数据,然后以树形结构展示出来,使用极其方便,效果如下:

在这里你可以逐级展开对象结构查看,特别的方便,鼠标悬浮或者点击能展示该节点的基本描述信息。

获取源码

https://k8s.mybatis.io

目前提供了了 v1.12~v1.19 版本的文档,只包含最主要的结构信息,更多的内容还没有想好如何在树形结构上展示,如果你想获得源码或者获得结构化数据,可以参考文档首页随意捐赠金额留下邮箱即可获取。

结构化文档

结构化文档部分内容示例:


  "container-v1-core": 
    "id": "container-v1-core",
    "name": "Container v1 core",
    "primitive": false,
    "description": "Container v1 core",
    "group": "core",
    "version": "v1",
    "kind": "Container",
    "warning": 
      "text": "Warning: Containers are only ever created within the context of a Pod. This is usually done using a Controller. See Controllers: Deployment, Job, or StatefulSet",
      "html": "\\u003ci class\\u003d\\"fa fa-warning\\"\\u003e\\u003c/i\\u003e \\u003cb\\u003eWarning:\\u003c/b\\u003e\\nContainers are only ever created within the context of a \\u003ca href\\u003d\\"#pod-v1-core\\"\\u003ePod\\u003c/a\\u003e. This is usually done using a Controller. See Controllers: \\u003ca href\\u003d\\"#deployment-v1-apps\\"\\u003eDeployment\\u003c/a\\u003e, \\u003ca href\\u003d\\"#job-v1-batch\\"\\u003eJob\\u003c/a\\u003e, or \\u003ca href\\u003d\\"#statefulset-v1-apps\\"\\u003eStatefulSet\\u003c/a\\u003e"
    ,
    "fields": [
      
        "name": "args",
        "description": "Arguments to the entrypoint. The docker image\\u0027s CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container\\u0027s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell",
        "typeRefId": "string",
        "array": true
      ,
      
        "name": "command",
        "description": "Entrypoint array. Not executed within a shell. The docker image\\u0027s ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container\\u0027s environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell",
        "typeRefId": "string",
        "array": true
      ,
      
        "name": "env",
        "description": "List of environment variables to set in the container. Cannot be updated.",
        "typeRefId": "envvar-v1-core",
        "array": true,
        "patch": 
          "strategy": [
            "merge"
          ],
          "mergeKey": "name"
        
      ,
      
        "name": "envFrom",
        "description": "List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated.",
        "typeRefId": "envfromsource-v1-core",
        "array": true
      ,
      
        "name": "image",
        "description": "Docker image name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.",
        "typeRefId": "string",
        "array": false
      ,
      
        "name": "imagePullPolicy",
        "description": "Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images",
        "typeRefId": "string",
        "array": false
      ,
      
        "name": "lifecycle",
        "description": "Actions that the management system should take in response to container lifecycle events. Cannot be updated.",
        "typeRefId": "lifecycle-v1-core",
        "array": false
      ,
      
        "name": "livenessProbe",
        "description": "Periodic probe of container liveness. Container will be restarted if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes",
        "typeRefId": "probe-v1-core",
        "array": false
      ,
      
        "name": "name",
        "description": "Name of the container specified as a DNS_LABEL. Each container in a pod must have a unique name (DNS_LABEL). Cannot be updated.",
        "typeRefId": "string",
        "array": false
      ,
      
        "name": "ports",
        "description": "List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default \\"0.0.0.0\\" address inside a container will be accessible from the network. Cannot be updated.",
        "typeRefId": "containerport-v1-core",
        "array": true,
        "patch": 
          "strategy": [
            "merge"
          ],
          "mergeKey": "containerPort"
        
      ,
      
        "name": "readinessProbe",
        "description": "Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes",
        "typeRefId": "probe-v1-core",
        "array": false
      ,
      
        "name": "resources",
        "description": "Compute Resources required by this container. Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/",
        "typeRefId": "resourcerequirements-v1-core",
        "array": false
      ,
      
        "name": "securityContext",
        "description": "Security options the pod should run with. More info: https://kubernetes.io/docs/concepts/policy/security-context/ More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/",
        "typeRefId": "securitycontext-v1-core",
        "array": false
      ,
      
        "name": "startupProbe",
        "description": "StartupProbe indicates that the Pod has successfully initialized. If specified, no other probes are executed until this completes successfully. If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. This can be used to provide different probe parameters at the beginning of a Pod\\u0027s lifecycle, when it might take a long time to load data or warm a cache, than during steady-state operation. This cannot be updated. This is a beta feature enabled by the StartupProbe feature flag. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes",
        "typeRefId": "probe-v1-core",
        "array": false
      ,
      
        "name": "stdin",
        "description": "Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF. Default is false.",
        "typeRefId": "boolean",
        "array": false
      ,
      
        "name": "stdinOnce",
        "description": "Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false",
        "typeRefId": "boolean",
        "array": false
      ,
      
        "name": "terminationMessagePath",
        "description": "Optional: Path at which the file to which the container\\u0027s termination message will be written is mounted into the container\\u0027s filesystem. Message written is intended to be brief final status, such as an assertion failure message. Will be truncated by the node if greater than 4096 bytes. The total message length across all containers will be limited to 12kb. Defaults to /dev/termination-log. Cannot be updated.",
        "typeRefId": "string",
        "array": false
      ,
      
        "name": "terminationMessagePolicy",
        "description": "Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated.",
        "typeRefId": "string",
        "array": false
      ,
      
        "name": "tty",
        "description": "Whether this container should allocate a TTY for itself, also requires \\u0027stdin\\u0027 to be true. Default is false.",
        "typeRefId": "boolean",
        "array": false
      ,
      
        "name": "volumeDevices",
        "description": "volumeDevices is the list of block devices to be used by the container.",
        "typeRefId": "volumedevice-v1-core",
        "array": true,
        "patch": 
          "strategy": [
            "merge"
          ],
          "mergeKey": "devicePath"
        
      ,
      
        "name": "volumeMounts",
        "description": "Pod volumes to mount into the container\\u0027s filesystem. Cannot be updated.",
        "typeRefId": "volumemount-v1-core",
        "array": true,
        "patch": 
          "strategy": [
            "merge"
          ],
          "mergeKey": "mountPath"
        
      ,
      
        "name": "workingDir",
        "description": "Container\\u0027s working directory. If not specified, the container runtime\\u0027s default will be used, which might be configured in the container image. Cannot be updated.",
        "typeRefId": "string",
        "array": false
      
    ],
    "appears": [
      
        "typeRefId": "podspec-v1-core",
        "text": "PodSpec [core/v1]"
      
    ],
    "examples": 
      "example-container-v1-core": 
        "id": "example-container-v1-core",
        "name": "example",
        "heading": "Container Config to run nginx (must be embedded in a PodSpec to run).",
        "body": "name: nginx\\n# Run the nginx:1.14 image\\nimage: nginx:1.14",
        "html": "\\u003cpre class\\u003d\\"example\\"\\u003e\\u003ccode class\\u003d\\"lang-yaml\\"\\u003e\\nname: nginx\\n# Run the nginx:1.14 image\\nimage: nginx:1.14\\n\\n\\u003c/code\\u003e\\u003c/pre\\u003e"
      
    
  

提供的结构化数据就是每种类型的单一结构数据,项目页按树形结构展示时,是经过结构运算后的最终结构,经过运算后的数据结构在 10M 以上大小,为了传输更小,因此只提供了原始结构数据,想要获得最终运算数据时可以在前端源码 api-utils.js 的第 70 行代码前,添加 console.log(apiData) 来输出最终的结果。

版本比对

通过对比不同版本的数据还能轻松获取版本之间的变化,比如 v1.18 和 v1.19 之间的变化:

git patch 形式部分内容如下:

@@ -11,8 +11,8 @@
     "statefulset-v1-apps",
     "endpoints-v1-core",
     "endpointslice-v1beta1-discovery-k8s-io",
-    "ingress-v1beta1-networking-k8s-io",
-    "ingressclass-v1beta1-networking-k8s-io",
+    "ingress-v1-networking-k8s-io",
+    "ingressclass-v1-networking-k8s-io",
     "service-v1-core",
     "configmap-v1-core",
     "csidriver-v1-storage-k8s-io",
@@ -35,9 +35,8 @@
     "podpreset-v1alpha1-settings-k8s-io",
     "podsecuritypolicy-v1beta1-policy",
     "apiservice-v1-apiregistration-k8s-io",
-    "auditsink-v1alpha1-auditregistration-k8s-io",
     "binding-v1-core",
-    "certificatesigningrequest-v1beta1-certificates-k8s-io",
+    "certificatesigningrequest-v1-certificates-k8s-io",
     "clusterrole-v1-rbac-authorization-k8s-io",
     "clusterrolebinding-v1-rbac-authorization-k8s-io",
     "componentstatus-v1-core",
@@ -66,6 +65,8 @@
     "csidriver-v1beta1-storage-k8s-io",
     "csinode-v1beta1-storage-k8s-io",
     "csinodedriver-v1beta1-storage-k8s-io",
+    "certificatesigningrequest-v1beta1-certificates-k8s-io",
+    "certificatesigningrequestcondition-v1beta1-certificates-k8s-io",
     "clusterrole-v1beta1-rbac-authorization-k8s-io",
     "clusterrole-v1alpha1-rbac-authorization-k8s-io",
     "clusterrolebinding-v1beta1-rbac-authorization-k8s-io",
@@ -84,20 +85,29 @@
     "customresourcesubresources-v1beta1-apiextensions-k8s-io",
     "customresourcevalidation-v1beta1-apiextensions-k8s-io",
     "endpointport-v1beta1-discovery-k8s-io",
+    "event-v1-events-k8s-io",
     "event-v1beta1-events-k8s-io",
+    "eventseries-v1-events-k8s-io",
     "eventseries-v1beta1-events-k8s-io",
     "externaldocumentation-v1beta1-apiextensions-k8s-io",
     "externalmetricsource-v2beta1-autoscaling",
     "externalmetricstatus-v2beta1-autoscaling",
     "httpingresspath-v1beta1-extensions",
+    "httpingresspath-v1beta1-networking-k8s-io",
     "httpingressrulevalue-v1beta1-extensions",
+    "httpingressrulevalue-v1beta1-networking-k8s-io",
     "horizontalpodautoscaler-v2beta2-autoscaling",
     "horizontalpodautoscaler-v2beta1-autoscaling",
     "horizontalpodautoscalercondition-v2beta1-autoscaling",
     "ingress-v1beta1-extensions",
+    "ingress-v1beta1-networking-k8s-io",
     "ingressbackend-v1beta1-extensions",
+    "ingressbackend-v1beta1-networking-k8s-io",
+    "ingressclass-v1beta1-networking-k8s-io",
     "ingressrule-v1beta1-extensions",
+    "ingressrule-v1beta1-networking-k8s-io",
     "ingresstls-v1beta1-extensions",
+    "ingresstls-v1beta1-networking-k8s-io",
     "json-v1beta1-apiextensions-k8s-io",
     "jsonschemaprops-v1beta1-apiextensions-k8s-io",
     "jsonschemapropsorarray-v1beta1-apiextensions-k8s-io",
@@ -140,7 +150,6 @@
     "servicereference-v1beta1-admissionregistration-k8s-io",
     "servicereference-v1beta1-apiextensions-k8s-io",
     "servicereference-v1beta1-apiregistration-k8s-io",
-    "servicereference-v1alpha1-auditregistration-k8s-io",
     "storageclass-v1beta1-storage-k8s-io",
     "subject-v1-rbac-authorization-k8s-io",
     "subject-v1beta1-rbac-authorization-k8s-io",
@@ -160,8 +169,7 @@
     "volumenoderesources-v1beta1-storage-k8s-io",
     "webhookclientconfig-v1-apiextensions-k8s-io",
     "webhookclientconfig-v1beta1-admissionregistration-k8s-io",
-    "webhookclientconfig-v1beta1-apiextensions-k8s-io",
-    "webhookclientconfig-v1alpha1-auditregistration-k8s-io"
+    "webhookclientconfig-v1beta1-apiextensions-k8s-io"
   ],
   "types": 
     "null": 
@@ -890,13 +898,13 @@
         
       ]
     ,
-    "ingress-v1beta1-networking-k8s-io": 
-      "id": "ingress-v1beta1-networking-k8s-io",
-      "name": "Ingress v1beta1 networking.k8s.io",
+    "ingress-v1-networking-k8s-io": 
+      "id": "ingress-v1-networking-k8s-io",
+      "name": "Ingress v1 networking.k8s.io",
       "primitive": false,
-      "description": "Ingress v1beta1 networking.k8s.io",
+      "description": "Ingress v1 networking.k8s.io",
       "group": "networking.k8s.io",
-      "version": "v1beta1",
+      "version": "v1",
       "kind": "Ingress",

以上是关于方便的 Kubernetes API 参考文档的主要内容,如果未能解决你的问题,请参考以下文章

client-go 源码分析

使用 swagger-ui 可视化 Kubernetes API 文档

C# 开源一个基于 yarp 的 API 网关 Demo,支持绑定 Kubernetes Service

Java的API文档能不能放到桌面上的菜单栏中啊,那样方便查找

kubernetes中搭建 jumpserver 跳板机

与 Kubernetes 共存:API 的使用和管理