Chapter 6. Exploring the Kubernetes API and Key Metadata

In this chapter, we present recipes that address the basic interaction 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.1 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.

6.1 Discovering API Endpoints of the Kubernetes API Server

Problem

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

Solution

If you have access to the API server via an unauthenticated private port, you can directly issue HTTP requests to the API server and explore the various endpoints. For example, with Minikube, you can ssh inside the virtual machine (minikube ssh) and reach the API server on port 8080, as shown here:

$ curl localhost:8080/api/v1
...
{
      "name": "pods",
      "namespaced": true,
      "kind": "Pod",
      "verbs": [
        "create",
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "proxy",
        "update",
        "watch"
      ],
      "shortNames": [
        "po"
      ]
    },
...

In this listing you see an example of an object of kind Pod as well as the allowed operations on this subject, such as get and delete.

Tip

Alternatively, if you don’t have direct access to the machine the Kubernetes API server is running on, you can use kubectl to proxy the API locally. This will allow ...

Get Kubernetes Cookbook 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.