2

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.

3
  • can you share the exact client of k8s you are using in your java app ? which dependancy ? Commented Apr 9, 2020 at 11:05
  • @MickeyHove l am currently using the following: <groupId>io.kubernetes</groupId> <artifactId>client-java</artifactId> <version>8.0.0</version> Commented Apr 9, 2020 at 14:11
  • I have put an answer which I have used in a similar use case I needed. let me know if that helps you, and in case yes would appreciate mark that as the accepted answer Commented Apr 9, 2020 at 15:18

1 Answer 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

Sign up to request clarification or add additional context in comments.

4 Comments

This does surely help me in controlling the deployments, but, i won't be able to know if the deployment was successful or not right
you can have a health check in each of your deployment and let your java client query these health checks until it will resolve all services are up and running properly. Don't use the client to try understanding the k8s object but use it to work with exposed services each k8s object expose. It should answer your problem. Let me know if you need more clarifications
Thanks, I will implement it with this approach, thanks a lot
great :) happy to asist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.