天天看點

友善的 Kubernetes API 參考文檔

​​https://k8s.mybatis.io​​

關注過 K8s 的人可能都看過官方的 API 參考文檔:

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

這個文檔的形式如下圖所示:

友善的 Kubernetes API 參考文檔

如果你真正參考過這個文檔,你會發現這個文檔特别不好用,想要逐級檢視屬性資訊時,經常在錨點之間跳轉,無法從整體上看到完整的結構,非常難用!!!

為了友善使用這個文檔,我提取了整個文檔的結構化資料,然後以樹形結構展示出來,使用極其友善,效果如下:

友善的 Kubernetes API 參考文檔

在這裡你可以逐級展開對象結構檢視,特别的友善,滑鼠懸浮或者點選能展示該節點的基本描述資訊。

擷取源碼

​​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 之間的變化:

友善的 Kubernetes API 參考文檔
@@ -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",