Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 688
BlueChips23 Avatar asked Jan 28 '23 01:01

BlueChips23


2 Answers

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.

like image 78
alexandrevilain Avatar answered Jan 30 '23 15:01

alexandrevilain


There is another kubernetes jave client and here is the example of deployments

Note the official library is generated by swagger and not well organized (I think).

like image 41
Leon Avatar answered Jan 30 '23 15:01

Leon