Search code examples
kuberneteskubectl

How to describe kubernetes resource


I'm trying to get metadata for a given kubernetes resource. Similar to a describe for a REST end-point.

Is there a kubectl to get all possible things that I could provide for any k8s resource ?

For example for the deployment resource, it could be something like this.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: <type:String> 
        <desc: name for the deployment>
  namespace: <type:String>
             <desc: Valid namespace>
  annotations:
    ...

Thanks in advance !


Solution

  • You can use the kubectl explain CLI command:

    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.

    Example to view all Deployment associated fields:

    kubectl explain deployment --recursive

    You can dig into specific fields:

    kubectl explain deployment.spec.template

    You can also rely on Kubernetes API Reference Docs.