Kubectl documentation without starting Kubernetes

9/25/2018

I have installed a K8S cluster on laptop using Kubeadm and VirtualBox. It seems a bit odd that the cluster has to be up and running to see the documentation as shown below.

praveensripati@praveen-ubuntu:~$ kubectl explain pods
Unable to connect to the server: dial tcp 192.168.0.31:6443: connect: no route to host

Any workaround for this?

-- Praveen Sripati
documentation
kubernetes

3 Answers

9/25/2018

See "kubectl explain — #HeptioProTip"

Behind the scenes, kubectl just made an API request to my Kubernetes cluster, grabbed the current Swagger documentation of the API version running in the cluster, and output the documentation and object types.

Try kubectl help as an offline alternative, but that won't be as complete (limite to kubectl itself).

-- VonC
Source: StackOverflow

9/25/2018

So the rather sobering news is that AFAIK there's not out-of-the box way how to do it, though you could totally write a kubectl plugin (it has become rather trivial now in 1.12). But for now, the best I can offer is the following:

# figure out which endpoint kubectl uses to retrieve docs:
$ kubectl -v9 explain pods

# from above I learn that in my case it's apparently
# https://192.168.64.11:8443/openapi/v2 so let's curl that:
$ curl -k https://192.168.64.11:8443/openapi/v2 > resources-docs.json

From here you can, for example, use jq to query for the descriptions. It's not as nice as a proper explain, but kinda is a good enough workaround until someone writes an docs offline query kubectl plugin.

-- Michael Hausenblas
Source: StackOverflow

9/25/2018

The 'explain' documentation lives in the kube-apiserver and its resource definitions. Hence the need to connect to it through kubectl explain to get any docs. This is different from the standard very basic cli help from kubectl where it's in the kubectl Golang code.

So no workaround really other than setting up a dummy Kubernetes cluster and have kubectl point to it. Please note that CRDs help might not be available since they live in the deployed CRDs themselves.

-- Rico
Source: StackOverflow