简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM