Sunday, February 19, 2017

How to setup GKE?

I'm usually manage google cloud command in Postman.
Follow next orders.
  1. Create own network.
    curl -X POST -H "Content-Type: application/json" -H "Authorization: {{Your Access Token}}" -H "Cache-Control: no-cache" -d '{
      "name": "{{Your Network Name}}",
      "description": "{{Your Network Description}}",
      "autoCreateSubnetworks": false
    }' "https://www.googleapis.com/compute/v1/projects/{{Your Project ID}}/global/networks"
  2. Create subnetwork.
    curl -X POST -H "Content-Type: application/json" -H "Authorization: {{Your Access Token}}" -H "Cache-Control: no-cache" -d '{
      "ipCidrRange": "10.10.0.0/20",
      "name": "asia-east1",
      "network": "https://www.googleapis.com/compute/v1/projects/{{Your Project ID}}/global/networks/{{Your Network Name}}"
    }' "https://www.googleapis.com/compute/v1/projects/{{Your Project ID}}/regions/asia-east1/subnetworks"
  3. Create cluster in GKE.
    curl -X POST -H "Content-Type: application/json" -H "Authorization: {{Your Access Token}}" -H "Cache-Control: no-cache" -H "Postman-Token: bc7eddb2-be25-29f6-9af4-be948e1519b6" -d '{
      "cluster": {
        "name": "{{Your Cluster Name}}",
        "zone": "asia-east1-a",
        "network": "{{Your Network Name}},
        "loggingService": "logging.googleapis.com",
        "monitoringService": "none",
        "description": "{{Your Cluster Description}}",
        "subnetwork": "asia-east1",
        "nodePools": [
          {
            "initialNodeCount": 1,
            "config": {
              "machineType": "n1-standard-2",
              "imageType": "GCI",
              "diskSizeGb": 100,
              "localSsdCount": 1,
              "oauthScopes": [
                "https://www.googleapis.com/auth/compute",
                "https://www.googleapis.com/auth/devstorage.read_write",
                "https://www.googleapis.com/auth/bigquery",
                "https://www.googleapis.com/auth/sqlservice.admin",
                "https://www.googleapis.com/auth/datastore",
                "https://www.googleapis.com/auth/logging.write",
                "https://www.googleapis.com/auth/monitoring.write",
                "https://www.googleapis.com/auth/bigtable.data",
                "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": {}
            },
            "name": "{{Your Pool Name}}"
          }
        ],
        "masterAuth": {
          "username": "admin"
        }
      }
    }' "https://container.googleapis.com/v1/projects/{{Your Project ID}}/zones/asia-east1-a/clusters"
  4. Get credential of cluster.
    gcloud container clusters list
    gcloud config set container/cluster {{Your Cluster Name}}
    gcloud config set compute/zone {{Your Zone ID}}
    echo "export GOOGLE_APPLICATION_CREDENTIALS={{Your Key File Address}}" >> ~/.bash_profile
    gcloud container clusters get-credentials {{Your Cluster Name}}