# Using API to create GKE cluster

**URL:** <https://forums.suse.com/t/using-api-to-create-gke-cluster/13660>\
**Category:** SUSE Rancher Prime\
**Created:** [March 17, 2019, 2:29pm UTC](https://forums.suse.com/t/using-api-to-create-gke-cluster/13660 "2019-03-17T14:29:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hai\_Vu](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/hai_vu/32/4941_2.png) [@Hai\_Vu](https://forums.suse.com/u/Hai_Vu)\
**Post date:** [March 17, 2019, 2:29pm UTC](https://forums.suse.com/t/using-api-to-create-gke-cluster/13660/1 "2019-03-17T14:29:10Z")

</div>

Hi all, I am new to Rancher as well as to this forum so please bear with me. I have been searching for instruction on how to use the Rancher API (v3) to manage clusters on GKE, specifically creating clusters, and came up with very little from the internet. The quick start guide only showed examples with Digital Ocean and AWS. I am writing a custom NodeJS app to auto provision our Kubernetes apps (wrapped in Helm charts), a one click so to speak, to create clusters, and to deploy the selected apps, not unlike how a human uses the Rancher UI to do this in multiple steps. I got to the point where I was able to query all of the Rancher resources (schemas), via the API, I am now stuck at the cluster creation step, where I sent the cluster spec (with the embedded GKE config structure) along with the POST clusters command to Rancher, and got back some authorisation/authentication problem. In the Rancher UI, this is the point where you basically upload the GKE service account key (in JSON format) to proceed with the cluster creation process, I don’t know how to achieve this effect using the API. I tried pasting stuff into the googleKubernetesEngineConfig.credential which resulted in " Google: error getting credentials using GOOGLE\_APPLICATION\_CREDENTIALS environment variable: invalid character…"

If any one can point me to some documentation, instruction, or other thread(s) that might touch on this it would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Hai\_Vu](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/hai_vu/32/4941_2.png) [@Hai\_Vu](https://forums.suse.com/u/Hai_Vu)\
**Post date:** [March 17, 2019, 3:44pm UTC](https://forums.suse.com/t/using-api-to-create-gke-cluster/13660/2 "2019-03-17T15:44:34Z")

</div>

Oh, hey I figured out this part, the googleKubernetesEngineConfig.credential parameter should be set to the content of the aforementioned GKE service account key JSON file, as a string, not as a JSON object. So you would send a body of the clusters POST request something like so:  
{  
name = “_your cluster name goes here_”,  
googleKubernetesEngineConfig = {  
credential = “_content of service account key file goes here_”,  
diskSizeGb = 100, // Example  
machineType = “n1-highmem-2”, // Example  
projectId = “_project ID extracted from service account key file_”,  
zone = “northamerica-northeast1-a”, // Example  
}  
}

---

<div class="post-metadata">

**Author:** ![Sarma\_K](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Sarma\_K](https://forums.suse.com/u/Sarma_K)\
**Post date:** [July 15, 2019, 1:15pm UTC](https://forums.suse.com/t/using-api-to-create-gke-cluster/13660/3 "2019-07-15T13:15:05Z")

</div>

It took almost a day to figure out the correct json format to credential request.
