我有由 AKS 設定和管理的 Kubernetes 集群,我可以使用 python 客戶端訪問它。
問題是,當我嘗試發送補丁縮放請求時,我遇到了錯誤。
我在 GitHub 檔案中找到了有關從 python 客戶端擴展命名空間部署的資訊,但不清楚需要什么主體才能使請求作業:
# Enter a context with an instance of the API kubernetes.client
with kubernetes.client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = kubernetes.client.AppsV1Api(api_client)
name = 'name_example' # str | name of the Scale
namespace = 'namespace_example' # str | object name and auth scope, such as for teams and projects
body = None # object |
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)
dry_run = 'dry_run_example' # str | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed (optional)
field_manager = 'field_manager_example' # str | fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is required for apply requests (application/apply-patch) but optional for non-apply patch types (JsonPatch, MergePatch, StrategicMergePatch). (optional)
force = True # bool | Force is going to \"force\" Apply requests. It means user will re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply patch requests. (optional)
try:
api_response = api_instance.patch_namespaced_deployment_scale(name, namespace, body, pretty=pretty, dry_run=dry_run, field_manager=field_manager, force=force)
pprint(api_response)
except ApiException as e:
print("Exception when calling AppsV1Api->patch_namespaced_deployment_scale: %s\n" % e)
所以在運行我得到的代碼時 Reason: Unprocessable Entity
有誰知道身體應該是什么格式?例如,如果我想將部署擴展到 2 個副本,該怎么做?
uj5u.com熱心網友回復:
的body引數patch_namespaced_deployment_scale可以是JSONPatch檔案,正如 @RakeshGupta 在評論中顯示的那樣,但它也可以是部分資源清單。例如,這有效:
>>> api_response = api_instance.patch_namespaced_deployment_scale(
... name, namespace,
... [{'op': 'replace', 'path': '/spec/replicas', 'value': 2}])
(請注意,value需要是整數,而不是注釋中的字串。)
但這也有效:
>>> api_response = api_instance.patch_namespaced_deployment_scale(
... name, namespace,
... {'spec': {'replicas': 2}})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/410368.html
標籤:
