Search code examples
javakuberneteskubernetes-health-check

What's the Kubernetes Client-Java API to get all deployments


I've been exploring the Kubernetes-Client/Java library and I can't figure out the API call to get all the deployments.

I'm looking for the K8-Client/Java API call for this command:

kubectl get deployments
NAME             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
appservice1       3         3         3            3           5d
appservice2       3         3         3            3           1d
appservice3       1         1         1            1           22d

More specifically, I'm interested in determining the number of desired & current pods for each deployment (like above).


Solution

  • You can find all methods of the Kubernetes java client here: https://github.com/kubernetes-client/java/tree/master/kubernetes/docs

    What you're searching for is the listNamespacedDeployment or listDeploymentForAllNamespaces.

    The return type of those methods is V1DeploymentList so you'll find the V1DeploymentStatus which is containing all information about the current number of pods controlled by the deployment.