Getting a JSON Response from the Kubernetes API

This section shows how to retrieve raw data from the Kubernetes API by using kubectl and analyze the data as a JSON object for the parts of the resource.

Let's begin by implementing the following steps:

  1. Get the raw data with the following command:
kubectl get --raw /api/v1/namespaces/kube-system
  1. As a result, you will see a JSON response. Let's get the same command and format the output:
kubectl get --raw /api/v1/namespaces/kube-system | python -m json.tool

If Python is not locally installed, any online JSON formatter can be used by copying and pasting the output.

  1. The JSON response shows the structure of a Kubernetes API resource:
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2018-04-15T10:21:34Z",
"name": "kube-system",
"resourceVersion": "81",
"selfLink": "/api/v1/namespaces/kube-system",
"uid": "c5db1188-4096-11e8-903d-0800273b4d24"
},

Kubernetes API resources have "apiVersion" since all resources are versioned in the system. "kind" shows the type of the resource and "metadata" has all of the meta information, such as the creation timestamp, labels, or annotations. "spec" is the part where all properties of the resource are listed. Finally, most of the resources have a "status" section to show their state, errors, or messages (if any).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.142.62