Tools: Kubernetes Has a Free API — Here's How to Manage Clusters Programmatically (2026)

Tools: Kubernetes Has a Free API — Here's How to Manage Clusters Programmatically (2026)

API Access

Node.js Client

Create a Deployment

Watch for Changes

Scale Deployment

kubectl Essentials Kubernetes provides a powerful REST API for managing containers, deployments, services, and more. Every kubectl command is just an API call — and you can use it directly. Need to extract or automate web content at scale? Check out my web scraping tools on Apify — no coding required. Or email me at [email protected] for custom solutions. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# Start a proxy to the API server -weight: 500;">kubectl proxy --port=8001 # List pods -weight: 500;">curl http://localhost:8001/api/v1/namespaces/default/pods | jq .items[].metadata.name # Get deployments -weight: 500;">curl http://localhost:8001/apis/apps/v1/namespaces/default/deployments # Start a proxy to the API server -weight: 500;">kubectl proxy --port=8001 # List pods -weight: 500;">curl http://localhost:8001/api/v1/namespaces/default/pods | jq .items[].metadata.name # Get deployments -weight: 500;">curl http://localhost:8001/apis/apps/v1/namespaces/default/deployments # Start a proxy to the API server -weight: 500;">kubectl proxy --port=8001 # List pods -weight: 500;">curl http://localhost:8001/api/v1/namespaces/default/pods | jq .items[].metadata.name # Get deployments -weight: 500;">curl http://localhost:8001/apis/apps/v1/namespaces/default/deployments -weight: 500;">npm -weight: 500;">install @kubernetes/client-node -weight: 500;">npm -weight: 500;">install @kubernetes/client-node -weight: 500;">npm -weight: 500;">install @kubernetes/client-node import * as k8s from "@kubernetes/client-node"; const kc = new k8s.KubeConfig(); kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); const appsApi = kc.makeApiClient(k8s.AppsV1Api); // List pods const { body } = await k8sApi.listNamespacedPod("default"); body.items.forEach(pod => { console.log(`${pod.metadata.name}: ${pod.-weight: 500;">status.phase}`); }); import * as k8s from "@kubernetes/client-node"; const kc = new k8s.KubeConfig(); kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); const appsApi = kc.makeApiClient(k8s.AppsV1Api); // List pods const { body } = await k8sApi.listNamespacedPod("default"); body.items.forEach(pod => { console.log(`${pod.metadata.name}: ${pod.-weight: 500;">status.phase}`); }); import * as k8s from "@kubernetes/client-node"; const kc = new k8s.KubeConfig(); kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); const appsApi = kc.makeApiClient(k8s.AppsV1Api); // List pods const { body } = await k8sApi.listNamespacedPod("default"); body.items.forEach(pod => { console.log(`${pod.metadata.name}: ${pod.-weight: 500;">status.phase}`); }); const deployment = { metadata: { name: "my-app" }, spec: { replicas: 3, selector: { matchLabels: { app: "my-app" } }, template: { metadata: { labels: { app: "my-app" } }, spec: { containers: [{ name: "app", image: "nginx:latest", ports: [{ containerPort: 80 }], resources: { requests: { cpu: "100m", memory: "128Mi" }, limits: { cpu: "500m", memory: "256Mi" } } }] } } } }; await appsApi.createNamespacedDeployment("default", deployment); console.log("Deployment created!"); const deployment = { metadata: { name: "my-app" }, spec: { replicas: 3, selector: { matchLabels: { app: "my-app" } }, template: { metadata: { labels: { app: "my-app" } }, spec: { containers: [{ name: "app", image: "nginx:latest", ports: [{ containerPort: 80 }], resources: { requests: { cpu: "100m", memory: "128Mi" }, limits: { cpu: "500m", memory: "256Mi" } } }] } } } }; await appsApi.createNamespacedDeployment("default", deployment); console.log("Deployment created!"); const deployment = { metadata: { name: "my-app" }, spec: { replicas: 3, selector: { matchLabels: { app: "my-app" } }, template: { metadata: { labels: { app: "my-app" } }, spec: { containers: [{ name: "app", image: "nginx:latest", ports: [{ containerPort: 80 }], resources: { requests: { cpu: "100m", memory: "128Mi" }, limits: { cpu: "500m", memory: "256Mi" } } }] } } } }; await appsApi.createNamespacedDeployment("default", deployment); console.log("Deployment created!"); const watch = new k8s.Watch(kc); await watch.watch("/api/v1/namespaces/default/pods", {}, (type, pod) => { console.log(`${type}: ${pod.metadata.name} — ${pod.-weight: 500;">status.phase}`); }, (err) => console.error(err) ); const watch = new k8s.Watch(kc); await watch.watch("/api/v1/namespaces/default/pods", {}, (type, pod) => { console.log(`${type}: ${pod.metadata.name} — ${pod.-weight: 500;">status.phase}`); }, (err) => console.error(err) ); const watch = new k8s.Watch(kc); await watch.watch("/api/v1/namespaces/default/pods", {}, (type, pod) => { console.log(`${type}: ${pod.metadata.name} — ${pod.-weight: 500;">status.phase}`); }, (err) => console.error(err) ); const scale = { spec: { replicas: 5 } }; await appsApi.patchNamespacedDeploymentScale( "my-app", "default", scale, undefined, undefined, undefined, undefined, { headers: { "Content-Type": "application/merge-patch+json" } } ); const scale = { spec: { replicas: 5 } }; await appsApi.patchNamespacedDeploymentScale( "my-app", "default", scale, undefined, undefined, undefined, undefined, { headers: { "Content-Type": "application/merge-patch+json" } } ); const scale = { spec: { replicas: 5 } }; await appsApi.patchNamespacedDeploymentScale( "my-app", "default", scale, undefined, undefined, undefined, undefined, { headers: { "Content-Type": "application/merge-patch+json" } } ); -weight: 500;">kubectl get pods -o wide -weight: 500;">kubectl describe pod my-pod -weight: 500;">kubectl logs my-pod --tail=100 -f -weight: 500;">kubectl exec -it my-pod -- /bin/sh -weight: 500;">kubectl port-forward svc/my--weight: 500;">service 8080:80 -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl rollout -weight: 500;">restart deployment/my-app -weight: 500;">kubectl get pods -o wide -weight: 500;">kubectl describe pod my-pod -weight: 500;">kubectl logs my-pod --tail=100 -f -weight: 500;">kubectl exec -it my-pod -- /bin/sh -weight: 500;">kubectl port-forward svc/my--weight: 500;">service 8080:80 -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl rollout -weight: 500;">restart deployment/my-app -weight: 500;">kubectl get pods -o wide -weight: 500;">kubectl describe pod my-pod -weight: 500;">kubectl logs my-pod --tail=100 -f -weight: 500;">kubectl exec -it my-pod -- /bin/sh -weight: 500;">kubectl port-forward svc/my--weight: 500;">service 8080:80 -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl rollout -weight: 500;">restart deployment/my-app