A quick reference to Google Cloud Platform.
Created on: 2019-12-05
Tag: cheat_sheet
Warning
under heavy construction and not well organized
For Ubuntu we can use apt 1:
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list sudo apt-get install apt-transport-https ca-certificates gnupg curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - sudo apt-get update && sudo apt-get install google-cloud-sdk
Or we can use Docker 2:
sudo docker pull gcr.io/google.com/cloudsdktool/cloud-sdk:latest
To run like normal tool instead of using docker run, make an alias like:
alias gcloud_docker='sudo docker run gcr.io/google.com/cloudsdktool/cloud-sdk:latest gcloud $@'
See here for more Installation options.
to start using the gcloud tool:
gcloud init
Now follow alone the instructions to finish the setup.
to uninstall Google Cloud SDK or gcloud:
sudo apt remove --purge google-cloud-sdk sudo rm -rf $(gcloud info --format='value(config.paths.global_config_dir)';gcloud info --format='value(installation.sdk_root)') sudo rm /etc/apt/sources.list.d/google-cloud-sdk.list sudo rm /usr/share/keyrings/cloud.google.gpg
to connect with ssh first add ssh key with gcloud 3:
gcloud compute --project "$PROJECT" ssh --zone "$ZONE" "$INSTANCE-NAME"
after that we can login with:
ssh $PUBLIC_IP
If we forget this command, we don't need to worry as it is available in the drop down list located beside the SSH button on the VM instances page.
to copy file with scp from remote to local:
gcloud compute scp "$INSTANCE-NAME":/remote/path /local/path
to copy file with scp from local to remote:
gcloud compute scp /local/path "$INSTANCE-NAME":/remote/path
source: https://cloud.google.com/sdk/gcloud/reference/compute/scp
to push a docker image, we need to tag an image 4:
sudo docker tag $IMAGE:$STAG $GCR_HOSTNAME/$PROJECT_ID/$IMAGE:$TAG
$GCR_HOSTNAME could be:
gcr.io
us.gcr.io
eu.gcr.io
asia.gcr.io
Choose the one closest to you. Now push the image:
sudo docker push $GCR_HOSTNAME/$PROJECT_ID/$IMAGE:$TAG