使用 Kubernetes API 管理部署的副本计数 [英] Manage replicas count for deployment using Kubernetes API
问题描述
我想使用 Kubernetes API (v1beta1) 更改部署的复制(pod)数量.
I want to change the number of replications (pods) for a Deployment using the Kubernetes API (v1beta1).
现在我可以使用以下命令从 CLI 增加副本:
For now I'm able to increase the replicas from CLI using the command:
kubectl scale --replicas=3 deployment my-deployment
在 Kubernetes API 文档 中提到有是执行相同操作的 PUT 请求
In the Kubernetes API documentation it's mention that there is a PUT request to do the same
PUT /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale
但是没有关于如何去做的例子.
but there is no example of how to do it.
我不确定要在请求正文中发送什么才能执行更新.
I'm not sure what to send in the request body in order to perform the update.
推荐答案
最简单的方法是首先检索实际数据:
the easiest way is to retrieve the actual data first with:
GET /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale
这会给你一个 yaml 或 json 对象,你可以修改它并用 PUT
请求发回.
This will give you an yaml or json object which you can modify and send back with the PUT
request.
使用 curl,往返看起来像这样:
With curl the roundtrip look like this:
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
<小时>
或者,您可以只使用 PATCH
调用:
PAYLOAD='[{"op":"replace","path":"/spec/replicas","value":"3"}]'
curl -X PATCH -d$PAYLOAD -H 'Content-Type: application/json-patch+json' $API_URL
这篇关于使用 Kubernetes API 管理部署的副本计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!