How Do You Deploy a Kubernetes Cluster in Google Cloud Platform?

Updated on 8/18/19

Problem Scenario
How do you deploy a Kubernetes cluster in Google Cloud Platform?

Solution
There are three ways to do this.  (You could use the console in a web browser.  A second way is with a command line interface method.  A third way is with a REST API.)

Possible solution #1
One way is with the console. Log into Google Cloud Platform. From the console search for "kubernetes" and click on the "Kubernetes Engine Option." Click "Create cluster". Adjust the settings as you desire. Click the "Create" button.

Possible solution #2
A second way is with the glcoud command line.  At the top, click the ">_" icon to "Activate Shell" so you can run a gcloud command. In this next example, you will create a cluster of three nodes each with 1 GB of RAM in the us-central1-a zone.  To find out the project names at your disposal, run this command:
gcloud project lists

Assuming you have authenticated, you would run this gloud command (but change "project-name-123456" to your project name, which is often found in the URL when you are using GCP):

gcloud beta container --project "project-name-123456" clusters create "cluster-1" --zone "us-central1-a" --username "admin" --cluster-version "1.12.8-gke.10" --machine-type "custom-1-1024" --image-type "COS" --disk-size "100" --scopes "https://www.googleapis.com/auth/compute","https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --network "default" --enable-cloud-logging --enable-cloud-monitoring --subnetwork "default"

The cluster-version may need to be changed. The value for cluster-version has (1.12.8-gke.10) is current as of 8/18/19. The machine type value should be changed from "custom-1-1024" to one that is available in your project. To find this value, you may want to use step #1 but do not create the cluster. Step #1 can help you find the cluster-version or the machine type.

Possible solution #3
A third way is with the API.  In this next example, you will create a cluster of three nodes each with 1 GB of RAM in the us-central1-a zone.

POST https://container.googleapis.com/v1/projects/project-name-123456/zones/us-central1-a/clusters
{
  "cluster": {
    "name": "cluster-1",
    "zone": "us-central1-a",
    "network": "default",
    "nodePools": [
      {
        "name": "default-pool",
        "initialNodeCount": 3,
        "config": {
          "machineType": "custom-1-1024",
          "imageType": "COS",
          "diskSizeGb": 100,
          "preemptible": false,
          "oauthScopes": [
            "https://www.googleapis.com/auth/compute",
            "https://www.googleapis.com/auth/devstorage.read_only",
            "https://www.googleapis.com/auth/logging.write",
            "https://www.googleapis.com/auth/monitoring",
            "https://www.googleapis.com/auth/servicecontrol",
            "https://www.googleapis.com/auth/service.management.readonly",
            "https://www.googleapis.com/auth/trace.append"
          ]
        },
        "autoscaling": {
          "enabled": false
        },
        "management": {
          "autoUpgrade": false,
          "autoRepair": false,
          "upgradeOptions": {}
        }
      }
    ],
    "loggingService": "logging.googleapis.com",
    "monitoringService": "monitoring.googleapis.com",
    "initialClusterVersion": "1.12.8-gke.10",
    "masterAuth": {
      "username": "admin",
      "clientCertificateConfig": {
        "issueClientCertificate": true
      }
    },
    "legacyAbac": {
      "enabled": false
    },
    "masterAuthorizedNetworksConfig": {
      "enabled": false,
      "cidrBlocks": []
    },
    "addonsConfig": {
      "kubernetesDashboard": {
        "disabled": false
      },
      "httpLoadBalancing": {
        "disabled": false
      },
      "networkPolicyConfig": {
        "disabled": true
      }
    },
    "networkPolicy": {
      "enabled": false,
      "provider": "CALICO"
    },
    "subnetwork": "default",
    "ipAllocationPolicy": {
      "useIpAliases": false
    }
  }
}

Leave a comment

Your email address will not be published. Required fields are marked *