Skip to content

Instantly share code, notes, and snippets.

@lefterisALEX
Forked from pydevops/gcloud-cheat-sheet.md
Created November 2, 2018 14:27
Show Gist options
  • Save lefterisALEX/b438d4b1552febd4bb18f1ff73b10e95 to your computer and use it in GitHub Desktop.
Save lefterisALEX/b438d4b1552febd4bb18f1ff73b10e95 to your computer and use it in GitHub Desktop.

Revisions

  1. @pydevops pydevops revised this gist Oct 19, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -344,6 +344,9 @@ gcloud compute project-info describe
    ```
    gcloud beta compute ssl-certificates create example-mydomain --domains example.mydomain.com
    gcloud beta compute ssl-certificates list
    gcloud beta compute ssl-certificates describe example-mydomain
    # It takes 30mins+ to provision the TLS, one of conditions is the target-https-proxies needs to be associated with the cert.
    gcloud beta compute target-https-proxies list
    ```


  2. @pydevops pydevops revised this gist Oct 18, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -340,6 +340,13 @@ leader=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/at
    gcloud compute project-info describe
    ```

    ## GCP managed ssl certificate
    ```
    gcloud beta compute ssl-certificates create example-mydomain --domains example.mydomain.com
    gcloud beta compute ssl-certificates list
    ```


    ## StackDriver logging
    ```
    gcloud logging read "timestamp >= \"2018-04-19T00:30:00Z\" and logName=projects/${project_id}/logs/requests and resource.type=http_load_balancer" --format="csv(httpRequest.remoteIp,httpRequest.requestUrl,timestamp)" --project=${project_id}
  3. Victor Yang revised this gist Oct 12, 2018. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -286,11 +286,6 @@ gcloud compute instances list --project=dev --filter="name~^es"
    gcloud compute instances list --project=dev --filter=name:kafka --format="value(name,INTERNAL_IP)"
    gcloud compute instances list --filter=tags:kafka-node
    gcloud compute instances list --filter='machineType:g1-small'
    gcloud compute instances list --filter=name:prod-es --format='value(NAME)' | xargs -I {} -p gcloud compute instances stop {}
    gcloud compute instances list --filter='name:prod-es*' --format='value(INTERNAL_IP)' | xargs -I {} ssh {} "sudo chef-client"
    ```

    ## move instance
    @@ -327,7 +322,6 @@ Use [gcloud compute operations describe URI] command to check the status of the
    ## regional disk
    ```
    gcloud beta compute instance attach-disk micro1 --disk pd-west1 --disk-scope regional
    gcloud beta compute instance detach-disk micro1 --disk pd-west1 --disk-scope regional
    ```

    ## debugging
    @@ -397,10 +391,9 @@ gcloud compute forwarding-rules list --format 'value(NAME)' | xargs -I {} gclou
    gcloud projects list --format='value(project_id)' | xargs -I {} gcloud compute addresses list --format='value(address)' --project {} 2>/dev/null | sort | uniq -c
    gcloud compute instances list --filter=elasticsearch --format='value(NAME)' | xargs -I {} -p gcloud compute instances stop {}
    gcloud compute instances list --filter=elasticsearch --format='value(INTERNAL_IP)' | xargs -I {} ssh {} "sudo chef-client"
    # delete non default routes
    gcloud compute routes list --filter="NOT network=default" --format='value(NAME)' | xargs -I {} gcloud compute routes delete -q {}
    ```

  4. Victor Yang revised this gist Oct 12, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -395,5 +395,12 @@ enable-service container.googleapis.com
    gcloud compute forwarding-rules list --format 'value(NAME)' | xargs -I {} gcloud compute forwarding-rules delete {} --region us-west1 -q
    gcloud projects list --format='value(project_id)' | xargs -I {} gcloud compute addresses list --format='value(address)' --project {} 2>/dev/null | sort | uniq -c
    gcloud compute instances list --filter=elasticsearch --format='value(NAME)' | xargs -I {} -p gcloud compute instances stop {}
    gcloud compute instances list --filter=elasticsearch --format='value(INTERNAL_IP)' | xargs -I {} ssh {} "sudo chef-client"
    ```

  5. Victor Yang revised this gist Oct 12, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -389,3 +389,11 @@ enable-service container.googleapis.com
    ## Client libraries you can use to connect to Google APIs
    * https://medium.com/google-cloud/simple-google-api-auth-samples-for-service-accounts-installed-application-and-appengine-da30ee4648


    ## chaining gcloud commands
    ```
    gcloud compute forwarding-rules list --format 'value(NAME)' | xargs -I {} gcloud compute forwarding-rules delete {} --region us-west1 -q
    gcloud projects list --format='value(project_id)' | xargs -I {} gcloud compute addresses list --format='value(address)' --project {} 2>/dev/null | sort | uniq -c
    ```

  6. Victor Yang revised this gist Oct 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -306,7 +306,7 @@ gcloud compute scp --recurse ../manifest <instance_name>:
    ```
    ### ssh port forwarding for elasticsearch
    ```
    gcloud compute --project "stage-23704" ssh --zone "us-central1-c" "elasticsearch-1" --ssh-flag="-L localhost:9200:localhost:9200"
    gcloud compute --project "foo" ssh --zone "us-central1-c" "elasticsearch-1" --ssh-flag="-L localhost:9200:localhost:9200"
    ```
    The 2nd `localhost` is relative to elasticsearch-1`

  7. Victor Yang revised this gist Oct 2, 2018. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ fi
    ```

    ## service account
    ## service account and IAM
    ```
    # creaate jenkins sa
    gcloud iam service-accounts create jenkins --display-name jenkins
    @@ -304,8 +304,13 @@ gcloud compute ssh --verbosity=debug <instance_name> --command "kubectl get node
    gcloud compute scp --recurse ../manifest <instance_name>:
    ```
    ### ssh port forwarding for elasticsearch
    ```
    gcloud compute --project "stage-23704" ssh --zone "us-central1-c" "elasticsearch-1" --ssh-flag="-L localhost:9200:localhost:9200"
    ```
    The 2nd `localhost` is relative to elasticsearch-1`

    ## generate ssh config
    ### generate ssh config
    ```
    gcloud compute config-ssh
    ```
  8. Victor Yang revised this gist Sep 25, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -122,10 +122,10 @@ gcloud iam service-accounts add-iam-policy-binding infrastructure@retviews-15490

    ```
    # user defined
    gcloud container builds submit --config=cloudbuild.yaml --substitutions=_BRANCH_NAME=foo,_BUILD_NUMBER=1 .
    gcloud builds submit --config=cloudbuild.yaml --substitutions=_BRANCH_NAME=foo,_BUILD_NUMBER=1 .
    # override built in TAG_NAME
    gcloud container builds submit --config=cloudbuild.yaml --substitutions=TAG_NAME=v1.0.1
    gcloud builds submit --config=cloudbuild.yaml --substitutions=TAG_NAME=v1.0.1
    ```

    ## kms
  9. Victor Yang revised this gist Sep 6, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@
    ```
    gcloud auth list
    gcloud auth login
    gcloud auth activate-service-account --key-file=sa_key.json
    ```

    kubectl uses OAuth token generated by
  10. Victor Yang revised this gist Sep 6, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -176,8 +176,6 @@ EOF
    gcloud compute instance-templates create nginx-template --metadata-from-file startup-script=startup.sh
    gcloud compute target-pools create nginx-pool
    gcloud compute instance-templates create nginx-template \
    --metadata-from-file startup-script=startup.sh
    gcloud compute instance-groups managed create nginx-group \
    --base-instance-name nginx \
    --size 2 \
  11. Victor Yang revised this gist Sep 6, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -173,6 +173,7 @@ apt-get install -y nginx
    service nginx start
    sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
    EOF
    gcloud compute instance-templates create nginx-template --metadata-from-file startup-script=startup.sh
    gcloud compute target-pools create nginx-pool
    gcloud compute instance-templates create nginx-template \
  12. Victor Yang revised this gist Sep 6, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -158,7 +158,7 @@ curl -v "https://cloudkms.googleapis.com/v1/projects/$DEVSHELL_PROJECT_ID/locati
    | jq .plaintext -r | base64 -d
    ```

    ## want to get the gcloud command for creating an instance?
    ## gcloud command for creating an instance?
    from web console
    ```
    gcloud beta compute --project=victory-demo-dev instances create micro1 --zone=us-west1-a --machine-type=f1-micro --subnet=default --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=398028291895-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 --min-cpu-platform=Automatic --image=debian-9-stretch-v20180510 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=micro1
  13. Victor Yang renamed this gist Sep 6, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  14. Victor Yang revised this gist Sep 6, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -117,7 +117,15 @@ gcloud iam service-accounts list --filter='email ~ [0-9]*-compute@.*' --form
    # add role to service account
    gcloud iam service-accounts add-iam-policy-binding [email protected] --member='serviceAccount:[email protected]' --role='roles/iam.serviceAccountActor'
    ```
    ## cloud build

    ```
    # user defined
    gcloud container builds submit --config=cloudbuild.yaml --substitutions=_BRANCH_NAME=foo,_BUILD_NUMBER=1 .
    # override built in TAG_NAME
    gcloud container builds submit --config=cloudbuild.yaml --substitutions=TAG_NAME=v1.0.1
    ```

    ## kms
    ```
  15. Victor Yang revised this gist Sep 3, 2018. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -34,9 +34,10 @@ gcloud compute zones list --filter=region:us-central1
    ## projects

    ```
    # get project_id
    project_id=$(gcloud config get-value core/project)
    project_id=$(gcloud config list project --format='value(core.project)')
    # various way to get project_id
    PROJECT_ID=$(gcloud config get-value core/project)
    PROJECT_ID=$(gcloud config list project --format='value(core.project)')
    PROJECT_ID=$(gcloud info --format='value(config.project)')
    # get project_number
    gcloud projects list --filter="name:${project_id}" --format='value(project_number)'
  16. Victor Yang revised this gist Aug 30, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -323,7 +323,8 @@ gcloud compute instances list --log-http

    ## instance level metadata
    ```
    curl "http://metadata.google.internal/computeMetadata/v1/instance/?recursive=true&alt=text" -H "Metadata-Flavor: Google"
    curl -s "http://metadata.google.internal/computeMetadata/v1/instance/?recursive=true&alt=text" -H "Metadata-Flavor: Google"
    leader=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/attributes/leader" -H "Metadata-Flavor: Google")
    ```

    ## project level metadata
  17. Victor Yang revised this gist Aug 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    * [projections](https://cloud.google.com/sdk/gcloud/reference/topic/projections)
    * [filters](https://cloud.google.com/sdk/gcloud/reference/topic/filters)
    * [resource-keys](https://cloud.google.com/sdk/gcloud/reference/topic/resource-keys)
    * https://cloud.google.com/sdk/docs/scripting-gcloud
    * [scripting-gcloud](https://cloud.google.com/sdk/docs/scripting-gcloud)
    * http://cloudplatform.googleblog.com/2018/03/introducing-GCPs-new-interactive-CLI.html
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-1-114924737
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-2-4d049a656f1a
  18. Victor Yang revised this gist Aug 29, 2018. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@
    * [resource-keys](https://cloud.google.com/sdk/gcloud/reference/topic/resource-keys)
    * https://cloud.google.com/sdk/docs/scripting-gcloud
    * http://cloudplatform.googleblog.com/2018/03/introducing-GCPs-new-interactive-CLI.html
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-1-114924737
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-2-4d049a656f1a

    ## auth
    ```
    @@ -116,10 +118,6 @@ gcloud iam service-accounts add-iam-policy-binding infrastructure@retviews-15490
    ```


    ## bash
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-1-114924737
    * https://medium.com/@Joachim8675309/getting-started-with-gcloud-sdk-part-2-4d049a656f1a

    ## kms
    ```
    # list all keyrings
    @@ -274,6 +272,7 @@ https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian
    * [resource-keys](https://cloud.google.com/sdk/gcloud/reference/topic/resource-keys)

    ```
    gcloud compute instances list --filter="zone:us-central1-a"
    gcloud compute instances list --project=dev --filter="name~^es"
    gcloud compute instances list --project=dev --filter=name:kafka --format="value(name,INTERNAL_IP)"
    gcloud compute instances list --filter=tags:kafka-node
  19. Victor Yang revised this gist Aug 29, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,14 @@ kubectl uses OAuth token generated by
    ```
    gcloud info --format flattened
    export PROJECT=$(gcloud info --format='value(config.project)')
    ```

    ## zones
    To return a list of zones given a region
    ```
    gcloud compute zones list --filter=region:us-central1
    ```

    ## projects

    ```
  20. Victor Yang revised this gist Aug 26, 2018. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -333,9 +333,12 @@ gcloud logging read "timestamp >= \"2018-04-19T00:30:00Z\" and logName=projects

    ## Enable Service
    ```
    gcloud services enable cloudapis.googleapis.com
    gcloud services enable cloudresourcemanager.googleapis.com
    gcloud services enable compute.googleapis.com
    # chain
    gcloud services enable cloudapis.googleapis.com && \
    cloudresourcemanager.googleapis.com && \
    compute.googleapis.com
    # or not chain
    gcloud services enable container.googleapis.com
    gcloud services enable containerregistry.googleapis.com
    gcloud services enable cloudbuild.googleapis.com
  21. Victor Yang revised this gist Aug 26, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -191,15 +191,13 @@ tag the instances with `no-ips`

    ```
    gcloud compute instances add-tags existing-instance --tags no-ip
    ```
    ```
    gcloud compute routes create no-ip-internet-route \
    --network custom-network1 \
    --destination-range 0.0.0.0/0 \
    --next-hop-instance nat-gateway \
    --next-hop-instance-zone us-central1-a \
    --tags no-ip --priority 800
    ```
    ```

    ## layer 3 network lb
    ```
  22. Victor Yang revised this gist Aug 26, 2018. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -186,6 +186,21 @@ gcloud compute instance-templates create nat-2 \
    --metadata-from-file=startup-script=startup.sh --address $nat_2_ip
    ```

    ### route
    tag the instances with `no-ips`

    ```
    gcloud compute instances add-tags existing-instance --tags no-ip
    ```
    ```
    gcloud compute routes create no-ip-internet-route \
    --network custom-network1 \
    --destination-range 0.0.0.0/0 \
    --next-hop-instance nat-gateway \
    --next-hop-instance-zone us-central1-a \
    --tags no-ip --priority 800
    ```
    ## layer 3 network lb
    ```
    gcloud compute firewall-rules create www-firewall --allow tcp:80
  23. Victor Yang revised this gist Aug 26, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -175,9 +175,15 @@ gcloud compute instance-groups managed create nginx-group \
    https://cloud.google.com/vpc/docs/special-configurations#multiple-natgateways

    ```
    gsutil cp gs://nat-gw-template/startup.sh .
    gcloud compute instance-templates create nat-1 \
    --machine-type n1-standard-2 --can-ip-forward --tags natgw \
    --metadata-from-file=startup-script=startup.sh --address $nat_1_ip
    gcloud compute instance-templates create nat-2 \
    --machine-type n1-standard-2 --can-ip-forward --tags natgw \
    --metadata-from-file=startup-script=startup.sh --address $nat_2_ip
    ```

    ## layer 3 network lb
  24. Victor Yang revised this gist Aug 26, 2018. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -171,6 +171,15 @@ gcloud compute instance-groups managed create nginx-group \
    --target-pool nginx-pool
    ```

    ### MIG with startup and shutdown scripts
    https://cloud.google.com/vpc/docs/special-configurations#multiple-natgateways

    ```
    gcloud compute instance-templates create nat-1 \
    --machine-type n1-standard-2 --can-ip-forward --tags natgw \
    --metadata-from-file=startup-script=startup.sh --address $nat_1_ip
    ```

    ## layer 3 network lb
    ```
    gcloud compute firewall-rules create www-firewall --allow tcp:80
  25. Victor Yang revised this gist Aug 16, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -254,6 +254,14 @@ gcloud compute instances list --filter='name:prod-es*' --format='value(INTERNAL_
    ## move instance
    `gcloud compute instances move <instance_wanna_move> --destination-zone=us-central1-a --zone=us-central1-c`

    ## ssh & scp
    ```
    #--verbosity=debug is great for debugging, showing the SSH command
    # the following is a real word example for running a bastion server that talks to a GKE cluster (master authorized network)
    gcloud compute ssh --verbosity=debug <instance_name> --command "kubectl get nodes"
    gcloud compute scp --recurse ../manifest <instance_name>:
    ```

    ## generate ssh config
    ```
  26. Victor Yang revised this gist Aug 13, 2018. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions gcp_gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,16 @@ kubectl uses OAuth token generated by
    gcloud info --format flattened
    export PROJECT=$(gcloud info --format='value(config.project)')
    ```
    ## projects

    ```
    # get project_id
    project_id=$(gcloud config get-value core/project)
    project_id=$(gcloud config list project --format='value(core.project)')
    # get project_number
    gcloud projects list --filter="name:${project_id}" --format='value(project_number)'
    ```

    ## switch gcloud context with gcloud config
    @@ -34,8 +44,7 @@ gcloud config set compute/region us-west1
    gcloud config set compute/zone us-west1-a
    alias demo='gcloud config set account [email protected] && gcloud config set project salt-163215 && gcloud config set compute/region us-west1 && gcloud config set compute/zone us-west1-a'
    project_id=$(gcloud config get-value core/project)
    project_id=$(gcloud config list project --format='value(core.project)')
    cluster=$(gcloud config get-value container/cluster 2> /dev/null)
    zone=$(gcloud config get-value compute/zone 2> /dev/null)
  27. Victor Yang renamed this gist Aug 12, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  28. @pydevops pydevops revised this gist Jun 25, 2018. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,20 @@ gcloud config set project $(gcloud projects list --filter='name:wordpress-dev' -
    # get the GKE cluster endpoint
    gcloud container clusters describe mycluster --zone $(gcloud config get-value compute/zone) --format='get(endpoint)'
    ```

    ```
    command -v gcloud >/dev/null 2>&1 || { \
    echo >&2 "I require gcloud but it's not installed. Aborting."; exit 1; }
    REGION=$(gcloud config get-value compute/region)
    if [[ -z "${REGION}" ]]; then
    echo "https://cloud.google.com/compute/docs/regions-zones/changing-default-zone-region" 1>&2
    echo "gcloud cli must be configured with a default region." 1>&2
    echo "run 'gcloud config set compute/region REGION'." 1>&2
    echo "replace 'REGION' with the region name like us-west1." 1>&2
    exit 1;
    fi
    ```

  29. @pydevops pydevops revised this gist Jun 20, 2018. 1 changed file with 17 additions and 6 deletions.
    23 changes: 17 additions & 6 deletions gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -267,18 +267,29 @@ curl "http://metadata.google.internal/computeMetadata/v1/instance/?recursive=tru
    gcloud compute project-info describe
    ```

    ## GCR
    * https://gist.github.com/ahmetb/7ce6d741bd5baa194a3fac6b1fec8bb7
    * https://medium.com/google-cloud/gcr-io-tips-tricks-d80b3c67cb64

    ## StackDriver logging
    ```
    gcloud logging read "timestamp >= \"2018-04-19T00:30:00Z\" and logName=projects/${project_id}/logs/requests and resource.type=http_load_balancer" --format="csv(httpRequest.remoteIp,httpRequest.requestUrl,timestamp)" --project=${project_id}
    ```

    ## Enable Service
    ```
    function enable-api() {
    gcloud services enable cloudapis.googleapis.com
    gcloud services enable cloudresourcemanager.googleapis.com
    gcloud services enable compute.googleapis.com
    gcloud services enable container.googleapis.com
    gcloud services enable containerregistry.googleapis.com
    gcloud services enable cloudbuild.googleapis.com
    gcloud services enable iam.googleapis.com
    gcloud services enable logging.googleapis.com
    gcloud services enable monitoring.googleapis.com
    gcloud services enable storage-api.googleapis.com
    gcloud services enable storage-component.googleapis.com
    gcloud services enable sourcerepo.googleapis.com
    ```

    ```
    function enable-service() {
    SERVICE=$1
    if [[ $(gcloud services list --format="value(serviceConfig.name)" \
    --filter="serviceConfig.name:$SERVICE" 2>&1) != \
    @@ -290,7 +301,7 @@ function enable-api() {
    fi
    }
    enable-api container.googleapis.com
    enable-service container.googleapis.com
    ```

    ## Client libraries you can use to connect to Google APIs
  30. @pydevops pydevops revised this gist Jun 20, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gcloud_cheat_sheet.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ project=$(gcloud config get-value core/project 2> /dev/null)
    gcloud config set project $(gcloud projects list --filter='name:wordpress-dev' --format='value(project_id)')
    # get the GKE cluster endpoint
    gcloud container clusters describe porch-development --zone $(gcloud config get-value compute/zone) --format='get(endpoint)'
    gcloud container clusters describe mycluster --zone $(gcloud config get-value compute/zone) --format='get(endpoint)'
    ```