Programmatically creating GKE clusters

12/18/2018

I would like to programmatically create GKE clusters (and resize them etc.). To do so, I could use the gscloud commands, but I found this java library that seems to imply that one can create/resize/delete clusters all from within java: https://developers.google.com/api-client-library/java/apis/container/v1 library (Note: This is a DIFFERENT library from the Java libraries for Kubernetes, which is well documented. The above link is for creating the INITIAL cluster, not starting up / shutting down pods etc.)

However, I couldn't find any examples/sample code on how to do some basic commands, eg

a) get list of clusters and see if a cluster of a particular name is runing b) start up cluster of a particular name in a certain region with a certain number of nodes of a certain instance type c) wait until the cluster has fully started up from (b) d) etc.

Any one have any examples of using the java library to accomplish this?

Also, is there a "generic" java library for any Kubernetes cluster managerment (not just the Google GKE one? I couldn't find any. Again, there are libraries for pod management, but I couldn't find any for generic Kubernetes cluster management (ie create cluster etc.))

-- Jonathan Sylvester
google-kubernetes-engine
kubernetes

1 Answer

12/18/2018

You could consider using the Terraform GKE provider to programmatically create and mange GKE clusters. It is idempotent and tracks state. I'd consider it to be more stable than any standalone library implementation. Besides, this is a typical use case for Terraform.

-- Badri
Source: StackOverflow