Skip to content

Latest commit

 

History

History
99 lines (74 loc) · 2.19 KB

google_container.md

File metadata and controls

99 lines (74 loc) · 2.19 KB

gocloud container - gce

Configure Google Cloud credentials.

Download your service account credentials file from Google Cloud and save it as googlecloudinfo.json in your HOME/.gocloud directory.

You can also set the credentials as environment variables:

export PrivateKey =  "xxxxxxxxxxxx"
export Type =  "xxxxxxxxxxxx"
export ProjectID = "xxxxxxxxxxxx"
export PrivateKeyID = "xxxxxxxxxxxx"
export ClientEmail = "xxxxxxxxxxxx"
export ClientID = "xxxxxxxxxxxx"
export AuthURI = "xxxxxxxxxxxx"
export TokenURI = "xxxxxxxxxxxx"
export AuthProviderX509CertURL = "xxxxxxxxxxxx"
export ClientX509CertURL =  "xxxxxxxxxxxx"

Initialize library

import "github.com/cloudlibz/gocloud/gocloud"

googlecloud, _ := gocloud.CloudProvider(gocloud.Googleprovider)

Create cluster

  nodepools := []map[string]interface{}{
       {
	"name":  "default-pool",
	"initialNodeCount": 3,
	},
  }

  createcluster := map[string]interface{}{
    "Project":   "sheltermap-1493101612061",
     "Name"  :   "cluster-2",
     "Zone"  :    "us-central1-a",
    "nodePools" : nodepools,
  }

  resp, err := googlecloud.CreateCluster(createcluster)

  response := resp.(map[string]interface{})
  fmt.Println(response["body"])

Delete cluster

 deletecluster := map[string]string{
		"Project":   "sheltermap-1493101612061",
		"clusterId": "cluster-1",
		"Zone":      "us-central1-a",
	}

 resp , err := googlecloud.DeleteCluster(deletecluster)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Create service

  createservice := map[string]interface{}{
	"Project"   :   "sheltermap-1493101612061",
	"clusterId" :   "cluster-2",
	"Zone"      :   "us-central1-a",
	"Name"      :   "nodepool",
	}

  resp, err := googlecloud.CreateService(createservice)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])

Delete service

deleteservice := map[string]string{
		"Project":    "sheltermap-1493101612061",
		"clusterId":  "cluster-2",
		"Zone":       "us-central1-a",
		"nodePoolId": "nodepool",
	}

 resp, err := googlecloud.DeleteService(deleteservice)

 response := resp.(map[string]interface{})
 fmt.Println(response["body"])