Thursday, April 25, 2019

Google Cloud SDK Install and Configure


How to install Google Cloud SDK and Configure for Google Cloud Platform (GCP).

  1. Get access to https://console.cloud.google.com by getting a free tier account activated with your google account and a valid credit card.
  2. Google Cloud SDK is a command-line interface for controlling Google Cloud Platform products and services. 
  3. Download the file GoogleCloudSDKInstaller.exe from https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe (For Windows Platform) . For other platforms, please refer to https://cloud.google.com/sdk/
  4. Once downloaded double-click the installer executable file from downloads folder and complete the installation.
  5. Hold on folks, we are not done with the job yet.!!
  6. Now configure the cloud SDK installer for google  using gcloud init console command,  similar to below one: 




  7. Test the working of gcloud CLI by the command below:
    • gcloud compute images list /*To list the operating System images available by default in GCP */
    • gcloud compute zones list
      /*To list the availability zones available by default in GCP */
    • gcloud compute instances create demo-jenkins-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a /* To create an instance in gcp by passing relevant parameters */
    • gcloud compute instances describe <instance name>  /*To check for existing instance in gcp, use the command similar to below*/ 
    • Sample Output
    • >gcloud compute instances describe demo-tomcat-instance-1 

    • canIpForward: false

      cpuPlatform: Intel Haswell

      creationTimestamp: '2019-03-16T04:33:56.843-07:00'

      deletionProtection: false

      description: ''
      disks:
      - autoDelete: true
        boot: true
        deviceName: demo-tomcat-instance-1
        index: 0
        interface: SCSI
        kind: compute#attachedDisk
        licenses:
        - https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-7
        mode: READ_WRITE
        source: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/disks/demo-tomcat-instance-1
        type: PERSISTENT
      id: '7314555617687986636'
      kind: compute#instance
      labelFingerprint: 42WmSpB8rSM=
      machineType: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/machineTypes/n1-standard-1
      metadata:
        fingerprint: sKpdoLSMkQ8=
        kind: compute#metadata
      name: demo-tomcat-instance-1
      networkInterfaces:
      - accessConfigs:
        - kind: compute#accessConfig
          name: External NAT
          natIP: 34.73.246.154
          networkTier: PREMIUM
          type: ONE_TO_ONE_NAT
        fingerprint: mlzggKQryXg=
        kind: compute#networkInterface
        name: nic0
        network: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/global/networks/default
        networkIP: 10.142.0.5
        subnetwork: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/regions/us-east1/subnetworks/default
      scheduling:
        automaticRestart: true
        onHostMaintenance: MIGRATE
        preemptible: false
      selfLink: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b/instances/demo-tomcat-instance-1
      serviceAccounts:
      - email: 443849179644-compute@developer.gserviceaccount.com
        scopes:
        - https://www.googleapis.com/auth/devstorage.read_only
        - https://www.googleapis.com/auth/logging.write
        - https://www.googleapis.com/auth/monitoring.write
        - https://www.googleapis.com/auth/servicecontrol
        - https://www.googleapis.com/auth/service.management.readonly
        - https://www.googleapis.com/auth/trace.append
      startRestricted: false
      status: RUNNING
      tags:
        fingerprint: 42WmSpB8rSM=
      zone: https://www.googleapis.com/compute/v1/projects/subtle-poet-231812/zones/us-east1-b
    • >gcloud compute instances create demo-jenkins-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a

    • >gcloud compute instances create demo-ansible-instance-1 --image-project centos-cloud --image centos-7-v20190423 --machine-type n1-standard-1 --zone asia-northeast1-a




      Congratulations you have successfully created an instance in google cloud in no time. ssh using your project private key , user name and External IP. I use git bash (for windows https://git-scm.com/download/win) for taking remote ssh connections of servers.

      Please feel free to add in comments if you face any difficulties. I will be happy to help you.