Chapter 7. Exploring the Kubernetes API and Key Metadata

In this chapter, we present recipes that address basic interactions with Kubernetes objects as well as the API. Every object in Kubernetes, no matter if namespaced like a deployment or cluster-wide like a node, has certain fields available—​for example, metadata, spec, and status. The spec describes the desired state for an object (the specification), and the status captures the actual state of the object, managed by the Kubernetes API server.

7.1 Discovering the Kubernetes API Server’s Endpoints

Problem

You want to discover the various API endpoints available on the Kubernetes API server.

Solution

Here we assume you’ve spun up a development cluster like kind or Minikube locally. You can run kubectl proxy in a separate terminal. The proxy lets you easily access the Kubernetes server API with an HTTP client such as curl, without needing to worry about authentication and certificates. After running kubectl proxy, you should be able to reach the API server on port 8001, as shown here:

$ curl http://localhost:8001/api/v1/
{
  "kind": "APIResourceList",
  "groupVersion": "v1",
  "resources": [
    {
      "name": "bindings",
      "singularName": "",
      "namespaced": true,
      "kind": "Binding",
      "verbs": [
        "create"
      ]
    },
    {
      "name": "componentstatuses",
      "singularName": "",
      "namespaced": false,
      ...

This lists all the objects exposed by the Kubernetes API. At the top of the list you can see an example of an object with kind set to Binding as well as the ...

Get Kubernetes Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.