Manage the number of replicas to deploy using the Kubernetes API

I want to change the number of replicas (pods) for Deployment using the Kubernetes API (v1beta1).

Now I can increase the replicas from the CLI with the command:

kubectl scale --replicas=3 deployment my-deployment 

The Kubernetes API documentation mentions that there is a PUT request to do the same

 PUT /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale 

but there is no example how to do this.

I am not sure what to send to the body of the request to complete the update.

+4
source share
1 answer

The easiest way is to get the actual data first:

 GET /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale 

This will give you a yaml or json object that you can modify and send back with a PUT request.


With a spin, the circuit is as follows:

 API_URL="http://kubernetes:8080/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale" curl -H 'Accept: application/json' $API_URL > scale.json # edit scale.json curl -X PUT -d@scale.json -H 'Content-Type: application/json' $API_URL 

Alternatively, you can simply use the PATCH call:

 PAYLOAD='[{"op":"replace","path":"/spec/replicas","value":"3"}]' curl -X PATCH -d$PAYLOAD -H 'Content-Type: application/json-patch+json' $API_URL 
+3
source

Source: https://habr.com/ru/post/1263038/


All Articles