Saltar al contenido

¿Dónde está la lista completa de objetos de kubernetes?

Solución:

El siguiente comando muestra con éxito todos los objetos de kubernetes

kubectl api-resources

Ejemplo

[[email protected] ~]# kubectl api-resources
NAME                              SHORTNAMES       KIND
bindings                                           Binding
componentstatuses                 cs               ComponentStatus
configmaps                        cm               ConfigMap
endpoints                         ep               Endpoints
events                            ev               Event
limitranges                       limits           LimitRange
namespaces                        ns               Namespace
nodes                             no               Node
persistentvolumeclaims            pvc              PersistentVolumeClaim
persistentvolumes                 pv               PersistentVolume
pods                              po               Pod
podtemplates                                       PodTemplate
replicationcontrollers            rc               ReplicationController
resourcequotas                    quota            ResourceQuota
secrets                                            Secret
serviceaccounts                   sa               ServiceAccount
services                          svc              Service
initializerconfigurations                          InitializerConfiguration
mutatingwebhookconfigurations                      MutatingWebhookConfiguration
validatingwebhookconfigurations                    ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds         CustomResourceDefinition
apiservices                                        APIService
controllerrevisions                                ControllerRevision
daemonsets                        ds               DaemonSet
deployments                       deploy           Deployment
replicasets                       rs               ReplicaSet
statefulsets                      sts              StatefulSet
tokenreviews                                       TokenReview
localsubjectaccessreviews                          LocalSubjectAccessReview
selfsubjectaccessreviews                           SelfSubjectAccessReview
selfsubjectrulesreviews                            SelfSubjectRulesReview
subjectaccessreviews                               SubjectAccessReview
horizontalpodautoscalers          hpa              HorizontalPodAutoscaler
cronjobs                          cj               CronJob
jobs                                               Job
brpolices                         br,bp            BrPolicy
clusters                          rcc              Cluster
filesystems                       rcfs             Filesystem
objectstores                      rco              ObjectStore
pools                             rcp              Pool
certificatesigningrequests        csr              CertificateSigningRequest
leases                                             Lease
events                            ev               Event
daemonsets                        ds               DaemonSet
deployments                       deploy           Deployment
ingresses                         ing              Ingress
networkpolicies                   netpol           NetworkPolicy
podsecuritypolicies               psp              PodSecurityPolicy
replicasets                       rs               ReplicaSet
nodes                                              NodeMetrics
pods                                               PodMetrics
networkpolicies                   netpol           NetworkPolicy
poddisruptionbudgets              pdb              PodDisruptionBudget
podsecuritypolicies               psp              PodSecurityPolicy
clusterrolebindings                                ClusterRoleBinding
clusterroles                                       ClusterRole
rolebindings                                       RoleBinding
roles                                              Role
volumes                           rv               Volume
priorityclasses                   pc               PriorityClass
storageclasses                    sc               StorageClass
volumeattachments                                  VolumeAttachment

Nota: la versión de kubernate es la v1.12 *

kubectl version

El siguiente comando enumera todas las versiones de API compatibles:

$ kubectl api-versions

Puede obtener información un poco detallada de kube-apiserver API REST:

Conexión abierta a kube-apiserver

$ kubectl proxy &

Ahora puede descubrir los recursos de la API:

Esta solicitud le brinda todas las rutas existentes en apiserver (en formato JSON):

$ curl http://localhost:8001/

    "/apis/extensions/v1beta1",
    "/apis/networking.k8s.io",
    "/apis/networking.k8s.io/v1",
    "/apis/policy",
    "/apis/policy/v1beta1",
    "/apis/rbac.authorization.k8s.io",
    "/apis/rbac.authorization.k8s.io/v1",
 ...
   "/version"
  ]
}

Puede solicitar detalles sobre una ruta en particular:

curl http://localhost:8001/api/v1

...
    {
      "name": "configmaps",
      "singularName": "",
      "namespaced": true,
      "kind": "ConfigMap",
      "verbs": [
        "create",
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "update",
        "watch"
      ],
      "shortNames": [
        "cm"
      ]
    },
...

Esta información te ayuda a escribir kubectl comandos, por ejemplo:

$ kubectl get configmaps
$ kubectl get cm

Pero puede que le resulte más conveniente utilizar la documentación incorporada proporcionada por kubectl explain.

Por ejemplo, este comando le muestra una lista de objetos de Kubernetes:

$ kubectl explain

Puede tener información detallada sobre cualquiera de los recursos enumerados:

$ kubectl explain rc
$ kubectl explain rc.spec
$ kubectl explain rc.spec.selector

O puede imprimir una plantilla YAML completa (o parte) del objeto agregando la bandera –recursive:

$ kubectl explain rc --recursive
$ kubectl explain rc.metadata --recursive

Los enlaces en la descripción apuntan a la documentación sobre un objeto en particular. P.ej:

DESCRIPTION:
     If the Labels of a ReplicationController are empty, they are defaulted to
     be the same as the Pod(s) that the replication controller manages. Standard
     object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
     ObjectMeta is metadata that all persisted resources must have, which
     includes all objects users must create.

Si necesita una descripción completa con ejemplos, siempre puede encontrarla en la Referencia API oficial (o la versión anterior), mencionada por Matthew L Daniel

También puede encontrar una referencia de kubectl útil o una hoja de referencia de kubectl

Actualizar: Con el siguiente resumen, puede enumerar todos los objetos agrupados por versiones de API (incluidos los CRD). Puede resultar útil comprobar si un objeto está presente en más de un grupo de API y, por lo tanto, se puede aplicar más de una apiVersion en su manifiesto. (Para diferentes apiVersions, la configuración del objeto puede ser ligeramente diferente).

a=$(kubectl api-versions) ; for n in $a ; do echo ; echo "apiVersion: $n" ; kubectl api-resources --api-group="${n%/*}" ; done

Salida de ejemplo parcial:

...
apiVersion: autoscaling/v1
NAME                       SHORTNAMES   APIGROUP      NAMESPACED   KIND
horizontalpodautoscalers   hpa          autoscaling   true         HorizontalPodAutoscaler

apiVersion: autoscaling/v2beta1
NAME                       SHORTNAMES   APIGROUP      NAMESPACED   KIND
horizontalpodautoscalers   hpa          autoscaling   true         HorizontalPodAutoscaler

apiVersion: autoscaling/v2beta2
NAME                       SHORTNAMES   APIGROUP      NAMESPACED   KIND
horizontalpodautoscalers   hpa          autoscaling   true         HorizontalPodAutoscaler

apiVersion: batch/v1
NAME       SHORTNAMES   APIGROUP   NAMESPACED   KIND
cronjobs   cj           batch      true         CronJob
jobs                    batch      true         Job

apiVersion: batch/v1beta1
NAME       SHORTNAMES   APIGROUP   NAMESPACED   KIND
cronjobs   cj           batch      true         CronJob
jobs                    batch      true         Job

...

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

lista de recursos

$ kubectl api-resources -o wide 
    NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND                             VERBS
    bindings                                                                      true         Binding                          [create]
    componentstatuses                 cs                                          false        ComponentStatus                  [get list]
    configmaps                        cm                                          true         ConfigMap                        [create delete deletecollection get list patch update watch]
    endpoints                         ep                                          true         Endpoints                        [create delete deletecollection get list patch update watch]
    events                            ev                                          true         Event                            [create delete deletecollection get list patch update watch]
    limitranges                       limits                                      true         LimitRange                       [create delete deletecollection get list patch update watch]
    namespaces                        ns                                          false        Namespace                        [create delete get list patch update watch]
    nodes                             no                                          false        Node                             [create delete deletecollection get list patch update watch]
    persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim            [create delete deletecollection get list patch update watch]
    persistentvolumes                 pv                                          false        PersistentVolume                 [create delete deletecollection get list patch update watch]
    pods                              po                                          true         Pod                              [create delete deletecollection get list patch update watch]
    podtemplates                                                                  true         PodTemplate                      [create delete deletecollection get list patch update watch]
    replicationcontrollers            rc                                          true         ReplicationController            [create delete deletecollection get list patch update watch]
    resourcequotas                    quota                                       true         ResourceQuota                    [create delete deletecollection get list patch update watch]
    secrets                                                                       true         Secret                           [create delete deletecollection get list patch update watch]
    serviceaccounts                   sa                                          true         ServiceAccount                   [create delete deletecollection get list patch update watch]
    services                          svc                                         true         Service                          [create delete get list patch update watch]
    mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration     [create delete deletecollection get list patch update watch]
    validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration   [create delete deletecollection get list patch update watch]
    customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition         [create delete deletecollection get list patch update watch]
    apiservices                                    apiregistration.k8s.io         false        APIService                       [create delete deletecollection get list patch update watch]
    controllerrevisions                            apps                           true         ControllerRevision               [create delete deletecollection get list patch update watch]
    daemonsets                        ds           apps                           true         DaemonSet                        [create delete deletecollection get list patch update watch]
    deployments                       deploy       apps                           true         Deployment                       [create delete deletecollection get list patch update watch]
    replicasets                       rs           apps                           true         ReplicaSet                       [create delete deletecollection get list patch update watch]
    statefulsets                      sts          apps                           true         StatefulSet                      [create delete deletecollection get list patch update watch]
    tokenreviews                                   authentication.k8s.io          false        TokenReview                      [create]
    localsubjectaccessreviews                      authorization.k8s.io           true         LocalSubjectAccessReview         [create]
    selfsubjectaccessreviews                       authorization.k8s.io           false        SelfSubjectAccessReview          [create]
    selfsubjectrulesreviews                        authorization.k8s.io           false        SelfSubjectRulesReview           [create]
    subjectaccessreviews                           authorization.k8s.io           false        SubjectAccessReview              [create]
    horizontalpodautoscalers          hpa          autoscaling                    true         HorizontalPodAutoscaler          [create delete deletecollection get list patch update watch]
    cronjobs                          cj           batch                          true         CronJob                          [create delete deletecollection get list patch update watch]
    jobs                                           batch                          true         Job                              [create delete deletecollection get list patch update watch]
    certificatesigningrequests        csr          certificates.k8s.io            false        CertificateSigningRequest        [create delete deletecollection get list patch update watch]
    leases                                         coordination.k8s.io            true         Lease                            [create delete deletecollection get list patch update watch]
    events                            ev           events.k8s.io                  true         Event                            [create delete deletecollection get list patch update watch]
    ingresses                         ing          extensions                     true         Ingress                          [create delete deletecollection get list patch update watch]
    ingresses                         ing          networking.k8s.io              true         Ingress                          [create delete deletecollection get list patch update watch]
    networkpolicies                   netpol       networking.k8s.io              true         NetworkPolicy                    [create delete deletecollection get list patch update watch]
    runtimeclasses                                 node.k8s.io                    false        RuntimeClass                     [create delete deletecollection get list patch update watch]
    poddisruptionbudgets              pdb          policy                         true         PodDisruptionBudget              [create delete deletecollection get list patch update watch]
    podsecuritypolicies               psp          policy                         false        PodSecurityPolicy                [create delete deletecollection get list patch update watch]
    clusterrolebindings                            rbac.authorization.k8s.io      false        ClusterRoleBinding               [create delete deletecollection get list patch update watch]
    clusterroles                                   rbac.authorization.k8s.io      false        ClusterRole                      [create delete deletecollection get list patch update watch]
    rolebindings                                   rbac.authorization.k8s.io      true         RoleBinding                      [create delete deletecollection get list patch update watch]
    roles                                          rbac.authorization.k8s.io      true         Role                             [create delete deletecollection get list patch update watch]
    priorityclasses                   pc           scheduling.k8s.io              false        PriorityClass                    [create delete deletecollection get list patch update watch]
    csidrivers                                     storage.k8s.io                 false        CSIDriver                        [create delete deletecollection get list patch update watch]
    csinodes                                       storage.k8s.io                 false        CSINode                          [create delete deletecollection get list patch update watch]
    storageclasses                    sc           storage.k8s.io                 false        StorageClass                     [create delete deletecollection get list patch update watch]
    volumeattachments                              storage.k8s.io                 false        VolumeAttachment                 [create delete deletecollection get list patch update watch]

detalles sobre cada objeto

    $ kubectl explain --help
    List the fields for supported resources

     This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier:

      <type>.<fieldName>[.<fieldName>]

 Add the --recursive flag to display all of the fields at once without descriptions. Information about each field is retrieved from the server in OpenAPI format.

Use "kubectl api-resources" for a complete list of supported resources.

Examples:
  # Get the documentation of the resource and its fields
  kubectl explain pods

  # Get the documentation of a specific field of a resource
  kubectl explain pods.spec.containers

Options:
      --api-version='': Get different explanations for particular API version
      --recursive=false: Print the fields of fields (Currently only 1 level deep)

Usage:
  kubectl explain RESOURCE [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)


Tags : /

Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *