Skip to content

dennyzhang/cheatsheet-gcp-A4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

1 GCP CheatSheet

linkedin
github
slack


PRs Welcome

File me Issues or star this repo.

1.1 GCP Basic

NameSummary
Official DocLink: gcloud reference, Link: gsutil tool
gsutil installationLink: install crcmod, Link: Install gsutil
InstallationLink: Install gcloud
Check version & settingsgcloud version, gcloud info, gcloud components list
Init profilegcloud init This will ask you to open an OpenID URL
List all zonesgcloud compute zones list
Upgrade local SDKgcloud components update, gcloud components update --version 219.0.1

1.2 Bucket Basic

NameSummary
List all buckets and filesgsutil ls, gsutil ls -lh gs://<bucket-name>
Download filegsutil cp gs://<bucket-name>/<dir-path>/package-1.1.tgz .
Upload filegsutil cp <filename> gs://<bucket-name>/<directory>/
Cat filegsutil cat gs://<bucket-name>/<filepath>/
Delete filegsutil rm gs://<bucket-name>/<filepath>
Move filegsutil mv <src-filepath> gs://<bucket-name>/<directory>/<dest-filepath>
Copy foldergsutil cp -r ./conf gs://<bucket-name>/
Show disk usagegsutil du -h gs://<bucket-name/<directory>
Create bucketgsutil mb gs://<bucket-name>
Caculate file sha1sumgsha1sum syslog-migration-10.0.2.tgz, shasum syslog-migration-10.0.2.tgz
Gsutil helpgsutil help, gsutil help cp, gsutil help options
ReferenceLink: Quickstart: Using the gsutil Tool

1.3 GCP Project

NameSummary
List projectsgcloud config list, gcloud config list project
Show project infogcloud compute project-info describe
Switch projectgcloud config set project <project-id>

1.4 GKE

NameSummary
Display a list of credentialed accountsgcloud auth list
Set the active accountgcloud config set account <ACCOUNT>
Set kubectl contextgcloud container clusters get-credentials <cluster-name>
Change regiongcloud config set compute/region us-west
Change zonegcloud config set compute/zone us-west1-b
List all container clustersgcloud container clusters list

1.5 IAM

NameSummary
Authenticate clientgcloud auth activate-service-account --key-file <key-file>
Display a list of credentialed accountsgcloud auth list
Set the active accountgcloud config set account <ACCOUNT>
Auth to GCP Container Registrygcloud auth configure-docker
Print token for active accountgcloud auth print-access-token, gcloud auth print-refresh-token
Revoke previous generated credentialgcloud auth <application-default> revoke

1.6 Bucket Security

NameSummary
Make all files readablegsutil -m acl set -R -a public-read gs://<bucket-name>/
Config authgsutil config -a
Grant bucket accessgsutil iam ch user:[email protected]:objectCreator,objectViewer gs://<bucket-name>
Remove bucket accessgsutil iam ch -d user:[email protected]:objectCreator,objectViewer gs://<bucket-name>

1.7 VM

NameSummary
List all instancesgcloud compute instances list, gcloud compute instance-templates list
Show instance info=gcloud compute instances describe “<instance-name>” –project “<project-name>” –zone “us-west2-a”=
Stop an instancegcloud compute instances stop instance-2
Start an instancegcloud compute instances start instance-2
Create an instancegcloud compute instances create vm1 --image image-1 --tags test --zone "<zone>" --machine-type f1-micro
SSH to instance=gcloud compute ssh –project “<project-name>” –zone “<zone-name>” “<instance-name>”=
Download filesgcloud compute copy-files example-instance:~/REMOTE-DIR ~/LOCAL-DIR --zone us-central1-a
Upload filesgcloud compute copy-files ~/LOCAL-FILE-1 example-instance:~/REMOTE-DIR --zone us-central1-a

1.8 Disks & Volumes

NameSummary
List all disksgcloud compute disks list
List all disk typesgcloud compute disk-types list
List all snapshotsgcloud compute snapshots list
Create snapshotgcloud compute disks snapshot <diskname> --snapshotname <name1> --zone $zone

1.9 Network

NameSummary
List all networksgcloud compute networks list
Detail of one networkgcloud compute networks describe <network-name> --format json
Create networkgcloud compute networks create <network-name>
Create subnetgcloud compute networks subnets create subnet1 --network net1 --range 10.5.4.0/24
Get a static ipgcloud compute addresses create --region us-west2-a vpn-1-static-ip
List all ip addressesgcloud compute addresses list
Describe ip addressgcloud compute addresses describe <ip-name> --region us-central1
List all routesgcloud compute routes list
Referencealeccunningham gist: vpn-setup.sh

1.10 DNS

NameSummary
List of all record-sets in my_zonegcloud dns record-sets list --zone my_zone
List first 10 DNS recordsgcloud dns record-sets list --zone my_zone --limit=10

1.11 Firewall

NameSummary
List all firewall rulesgcloud compute firewall-rules list
List all forwarding rulesgcloud compute forwarding-rules list
Describe one firewall rulegcloud compute firewall-rules describe <rule-name>
Create one firewall rulegcloud compute firewall-rules create my-rule --network default --allow tcp:9200 tcp:3306
Update one firewall rulegcloud compute firewall-rules update default --network default --allow tcp:9200 tcp:9300

1.12 Images & Containers

NameSummary
List all imagesgcloud compute images list
List all container clustersgcloud container clusters list
Set kubectl contextgcloud container clusters get-credentials <cluster-name>

1.13 RDS

NameSummary
List all sql instancesgcloud sql instances list

1.14 Services

NameSummary
List my backend servicesgcloud compute backend-services list
List all my health check endpointsgcloud compute http-health-checks list
List all URL mapsgcloud compute url-maps list

1.15 More Resources

kelseyhightower gist: create-global-lb.sh

mingderwang gist: gistfile1.txt

License: Code is licensed under MIT License.

linkedin github slack