Scaling and listing deployments via Kubernetes HTTP API?

6/1/2020

I'm trying to scale up/down some deployments over HTTP and also list the deployments on my cluster. I'm able to list pods, but can't figure out the deployments piece.

http://localhost:8080/api/v1/namespaces/default/deployments

{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "the server could not find the requested resource",
    "reason": "NotFound",
    "details": {},
    "code": 404
}
-- Ryan
kubernetes

1 Answer

6/2/2020

Deployments are in the apps/v1 namespace, and you need to include apps in the URL. The API documentation for the "list deployments" endpoint gives the URL as

GET /apis/apps/v1/namespaces/{namespace}/deployments

You can use the normal read-modify-write sequence to change the replicas: field in a deployment spec to scale it.

There is also a dedicated endpoint to scale deployments, though it's slightly underdocumented. Manage replicas count for deployment using Kubernetes API suggests reading and patching the scale resource, or there is an example with a minimal JSON payload.

-- David Maze
Source: StackOverflow