Kubernetes Rest Api 篇之四kubectl explain -- 查看api帮助

kubectl api-versions 查看组版名和组版
[root@k2 conf]# kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
management.cattle.io/v3
monitoring.coreos.com/v1
networking.k8s.io/v1
policy/v1beta1
project.cattle.io/v3
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
查看组rest api下的资源访问规则和访问的url
和 curl http://localhost:8080/ 结果是一致的
[root@k2 conf]# kubectl get --raw /
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/",
    "/apis/admissionregistration.k8s.io",
    "/apis/admissionregistration.k8s.io/v1beta1",
    "/apis/apiextensions.k8s.io",
    "/apis/apiextensions.k8s.io/v1beta1",
    "/apis/apiregistration.k8s.io",
    "/apis/apiregistration.k8s.io/v1",
    "/apis/apiregistration.k8s.io/v1beta1",
    "/apis/apps",
    "/apis/apps/v1",
    "/apis/apps/v1beta1",
    "/apis/apps/v1beta2",
    "/apis/authentication.k8s.io",
    "/apis/authentication.k8s.io/v1",
    "/apis/authentication.k8s.io/v1beta1",
    "/apis/authorization.k8s.io",
    "/apis/authorization.k8s.io/v1",
    "/apis/authorization.k8s.io/v1beta1",
    "/apis/autoscaling",
    "/apis/autoscaling/v1",
    "/apis/autoscaling/v2beta1",
    "/apis/batch",
    "/apis/batch/v1",
    "/apis/batch/v1beta1",
    "/apis/certificates.k8s.io",
    "/apis/certificates.k8s.io/v1beta1",
    "/apis/events.k8s.io",
    "/apis/events.k8s.io/v1beta1",
    "/apis/extensions",
    "/apis/extensions/v1beta1",
    "/apis/management.cattle.io",
    "/apis/management.cattle.io/v3",
    "/apis/monitoring.coreos.com",
    "/apis/monitoring.coreos.com/v1",
    "/apis/networking.k8s.io",
    "/apis/networking.k8s.io/v1",
    "/apis/policy",
    "/apis/policy/v1beta1",
    "/apis/project.cattle.io",
    "/apis/project.cattle.io/v3",
    "/apis/rbac.authorization.k8s.io",
    "/apis/rbac.authorization.k8s.io/v1",
    "/apis/rbac.authorization.k8s.io/v1beta1",
    "/apis/storage.k8s.io",
    "/apis/storage.k8s.io/v1",
    "/apis/storage.k8s.io/v1beta1",
    "/healthz",
    "/healthz/autoregister-completion",
    "/healthz/etcd",
    "/healthz/ping",
    "/healthz/poststarthook/apiservice-openapi-controller",
    "/healthz/poststarthook/apiservice-registration-controller",
    "/healthz/poststarthook/apiservice-status-available-controller",
    "/healthz/poststarthook/bootstrap-controller",
    "/healthz/poststarthook/ca-registration",
    "/healthz/poststarthook/generic-apiserver-start-informers",
    "/healthz/poststarthook/kube-apiserver-autoregistration",
    "/healthz/poststarthook/rbac/bootstrap-roles",
    "/healthz/poststarthook/start-apiextensions-controllers",
    "/healthz/poststarthook/start-apiextensions-informers",
    "/healthz/poststarthook/start-kube-aggregator-informers",
    "/healthz/poststarthook/start-kube-apiserver-informers",
    "/logs",
    "/metrics",
    "/openapi/v2",
    "/swagger-2.0.0.json",
    "/swagger-2.0.0.pb-v1",
    "/swagger-2.0.0.pb-v1.gz",
    "/swagger-ui/",
    "/swagger.json",
    "/swaggerapi",
    "/version"
  ]
}
curl http://localhost:8080/api/v1/nodes | more
和 [root@k2 conf]# kubectl get --raw /api/v1/nodes | python -m json.tool | more
一致,只是输出格式不一样.
[root@k2 conf]# curl http://localhost:8080/api/v1/nodes | more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{
  "kind": "NodeList",
  "apiVersion": "v1",
  "metadata": {
    "selfLink": "/api/v1/nodes",
    "resourceVersion": "324105400"
  },
  "items": [
    {
      "metadata": {
        "name": "ht1.node",
        "selfLink": "/api/v1/nodes/ht10.node",
        "uid": "735b2d85-be3b-11ec-95ea-060eb4000e9d",
        "resourceVersion": "324105389",
        "creationTimestamp": "2022-04-17T10:45:08Z",
        "labels": {
          "beta.kubernetes.io/arch": "amd64",
          "beta.kubernetes.io/os": "linux",
          "kubernetes.io/hostname": "ht1.node",
          "node-role.kubernetes.io/k8s-node": "true",
          "role": "ht"
........
//查看apps/v1下的api资源情况
kubectl get --raw /api/v1/nodes | python -m json.tool (自动格式化)
[root@k2 conf]# kubectl get --raw /apis/apps/v1  (手工格式化)
{
    "kind":"APIResourceList",
    "apiVersion":"v1",
    "groupVersion":"apps/v1",
    "resources":[
        {
            "name":"controllerrevisions",
            "singularName":"",
            "namespaced":true,
            "kind":"ControllerRevision",
            "verbs":[
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ]
        },
        {
            "name":"daemonsets",
            "singularName":"",
            "namespaced":true,
            "kind":"DaemonSet",
            "verbs":[
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ],
            "shortNames":[
                "ds"
            ],
            "categories":[
                "all"
            ]
        },
        {
            "name":"daemonsets/status",
            "singularName":"",
            "namespaced":true,
            "kind":"DaemonSet",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"deployments",
            "singularName":"",
            "namespaced":true,
            "kind":"Deployment",
            "verbs":[
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ],
            "shortNames":[
                "deploy"
            ],
            "categories":[
                "all"
            ]
        },
        {
            "name":"deployments/scale",
            "singularName":"",
            "namespaced":true,
            "group":"autoscaling",
            "version":"v1",
            "kind":"Scale",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"deployments/status",
            "singularName":"",
            "namespaced":true,
            "kind":"Deployment",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"replicasets",
            "singularName":"",
            "namespaced":true,
            "kind":"ReplicaSet",
            "verbs":[
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ],
            "shortNames":[
                "rs"
            ],
            "categories":[
                "all"
            ]
        },
        {
            "name":"replicasets/scale",
            "singularName":"",
            "namespaced":true,
            "group":"autoscaling",
            "version":"v1",
            "kind":"Scale",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"replicasets/status",
            "singularName":"",
            "namespaced":true,
            "kind":"ReplicaSet",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"statefulsets",
            "singularName":"",
            "namespaced":true,
            "kind":"StatefulSet",
            "verbs":[
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ],
            "shortNames":[
                "sts"
            ],
            "categories":[
                "all"
            ]
        },
        {
            "name":"statefulsets/scale",
            "singularName":"",
            "namespaced":true,
            "group":"autoscaling",
            "version":"v1",
            "kind":"Scale",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        },
        {
            "name":"statefulsets/status",
            "singularName":"",
            "namespaced":true,
            "kind":"StatefulSet",
            "verbs":[
                "get",
                "patch",
                "update"
            ]
        }
    ]
}

根据上面的举例查看某个资源的解释
kubectl explain controllerrevisions --api-version apps/v1
[root@k2 conf]# kubectl explain controllerrevisions --api-version apps/v1
KIND:     ControllerRevision
VERSION:  apps/v1

DESCRIPTION:
     ControllerRevision implements an immutable snapshot of state data. Clients
     are responsible for serializing and deserializing the objects that contain
     their internal state. Once a ControllerRevision has been successfully
     created, it can not be updated. The API Server will fail validation of all
     requests that attempt to mutate the Data field. ControllerRevisions may,
     however, be deleted. Note that, due to its use by both the DaemonSet and
     StatefulSet controllers for update and rollback, this object is beta.
     However, it may be subject to name and representation changes in future
     releases, and clients should not depend on its stability. It is primarily
     for internal use by controllers.

FIELDS:
   apiVersion    <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

   data    <Object>
     Data is the serialized representation of the state.

   kind    <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds

   metadata    <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata

   revision    <integer> -required-
     Revision indicates the revision of the state represented by Data.

 

posted @ 2022-05-28 04:36  jinzi  阅读(15)  评论(0编辑  收藏  举报