如何在Java中使用Kubernetes客户端获取部署的状态。

huangapple go评论78阅读模式
英文:

How to get the status of deployment using kubernetes-client in java

问题

我正在尝试在Java中使用kubernetes-client执行json-patch,从而触发部署。示例代码如下:

ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(ClientBuilder.standard().build());
ExtensionsV1beta1Deployment deploy =
    PatchUtils.patch(
        ExtensionsV1beta1Deployment.class,
        () ->
            api.patchNamespacedDeploymentCall(
                deploymentName,
                namespace,
                new V1Patch(jsonPatchStr),
                null,
                null,
                null,
                null,
                null),
        V1Patch.PATCH_FORMAT_JSON_PATCH,
        api.getApiClient());

log.info("json-patching started for " + deploymentName + " , the deployment is: "
    + deploy);

json-patch正常工作,新的pod使用所需的更改被创建。理想情况下,我希望在所需的所有pod都被创建之前等待我的线程,然后继续进行下一个步骤。因此,我想寻求帮助,找出如何跟踪执行json-patch后部署的状态。

英文:

I am trying to use kubernetes-client in java to perform a json-patch which intern triggers a deployment. Sample code is as follows

 ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(ClientBuilder.standard().build());
  ExtensionsV1beta1Deployment deploy =
      PatchUtils.patch(
          ExtensionsV1beta1Deployment.class,
          () ->
              api.patchNamespacedDeploymentCall(
                  deploymentName,
                  namespace,
                  new V1Patch(jsonPatchStr),
                  null,
                  null,
                  null,
                  null,
                  null),
          V1Patch.PATCH_FORMAT_JSON_PATCH,
          api.getApiClient());

  log.info("json-patching started for " + deploymentName + " , the deployment is: "
      + deploy);

The json-patch is working and new pods are created with the required changes. Ideally, I want to wait my thread until all the required pods are created and then move on to my next time, so I wanted some help in finding out how to track the deployment status for the json-patch performed.

答案1

得分: 1

不要回答我要翻译的问题。以下是要翻译的内容:

"Instead of putting the tests on your java client, I would suggest to let k8s to deal with this kind of dependencies by adding startup probes

Basically it will let you deploy all pods in any order but will have a restriction of when the k8s would start the pods on a simple health check of another pod

英文:

Instead of putting the tests on your java client, I would suggest to let k8s to deal with this kind of dependencies by adding startup probes

Basically it will let you deploy all pods in any order but will have a restriction of when the k8s would start the pods on a simple health check of another pod

huangapple
  • 本文由 发表于 2020年4月9日 17:08:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/61117635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定