Cloud Native 4 min read

Directly Accessing the Kubernetes API with curl and Custom Code

This article explains how to bypass kubectl and interact directly with the Kubernetes API using curl or any programming language, covering API discovery, request construction, resource listing, watching, and modifying objects, while illustrating concepts with JavaScript examples and shared informers.

System Architect Go
System Architect Go
System Architect Go
Directly Accessing the Kubernetes API with curl and Custom Code

Kubernetes exposes a powerful API that lets you control every aspect of a cluster, usually hidden behind kubectl but fully accessible via HTTP requests.

The article first reviews how kubectl works: client‑side validation, YAML generation, runtime object construction, discovery of API server endpoints, and negotiation of the correct API call based on apiVersion and kind.

After the basics, it shows practical examples. Using kubectl proxy you can open a local tunnel to the API server, then retrieve resources directly. For instance, to list all Deployments you can run:

curl localhost:8001/apis/apps/v1/namespaces/{namespace}/deployments

To list all Pods: curl localhost:8001/api/v1/namespaces/{namespace}/pods The article also demonstrates how to watch for changes, e.g., watching Pods with: GET /api/v1/watch/namespaces/{namespace}/pods/{name} Direct API access enables scripting and automation, as shown by a small 130‑line JavaScript/TypeScript dashboard that performs two GET requests (list Pods and watch Pods) and renders the data.

It explains the shared informer pattern, where listing and watching resources are combined, and notes that the same approach works for creating or updating resources, such as patching a Deployment:

PATCH /apis/apps/v1/namespaces/{namespace}/deployments/{name}

Finally, the article mentions an experimental project, xlskubectl, which controls a Kubernetes cluster from Google Sheets, using the same shared informer concept.

Overall, the guide shows that any language can call the Kubernetes API, offering greater flexibility for automation and custom extensions.

cloud-nativeKubernetesAPIcurlkubectl
System Architect Go
Written by

System Architect Go

Programming, architecture, application development, message queues, middleware, databases, containerization, big data, image processing, machine learning, AI, personal growth.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.