How to describe kubernetes resource

10/21/2019

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 !

-- Aravind
kubectl
kubernetes

2 Answers

10/21/2019

Are you familiar with OpenApi/Swagger? Try to open the following file in swagger-ui https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json

If you have a live kubernetes api available the file should be available under /openapi/v2 like they describe here: https://kubernetes.io/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions

-- bjartek
Source: StackOverflow

10/21/2019

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.

-- Eduardo Baitello
Source: StackOverflow