使用Kubernetes API管理副本数以进行部署 [英] Manage replicas count for deployment using Kubernetes API

查看:210
本文介绍了使用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.

卷曲后,往返行程如下:

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调用:


Alternatively you could just use a PATCH call:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆