Difference between revisions of "GCP/gcloud cli"
< GCP
Jump to navigation
Jump to search
(→Verify) |
|||
| Line 141: | Line 141: | ||
gcloud info | gcloud info | ||
Google Cloud SDK [253.0.0] | Google Cloud SDK [253.0.0] | ||
... | |||
# Verify gcloud project context | |||
$ gcloud info | grep '\(Google\|Account\|Project\)' | $ gcloud info | grep '\(Google\|Account\|Project\)' | ||
Google Cloud SDK [277.0.0] | Google Cloud SDK [277.0.0] | ||
Account: [user1@gmail.com] | Account: [user1@gmail.com] | ||
Project: [ | Project: [kinetic-physics-111111] | ||
</source> | </source> | ||
Revision as of 01:13, 21 October 2020
Install gcloud cli
# Ubuntu 18.04 LTS, 20.04; Oct 2020 sudo apt-get install apt-transport-https ca-certificates gnupg # Add the Cloud SDK distribution URI as a package source 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 # Import the Google Cloud Platform public key curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - # Update the package list and install the Cloud SDK sudo apt-get update && sudo apt-get install google-cloud-sdk # Additional packages are available: # google-cloud-sdk-app-engine-python # google-cloud-sdk-app-engine-python-extras # google-cloud-sdk-app-engine-java # google-cloud-sdk-app-engine-go # google-cloud-sdk-bigtable-emulator # google-cloud-sdk-cbt # google-cloud-sdk-cloud-build-local # google-cloud-sdk-datalab # google-cloud-sdk-datastore-emulator # google-cloud-sdk-firestore-emulator # google-cloud-sdk-pubsub-emulator # kubectl # <- interesting YEAH!
Initialize
# Verify SDK version and connected account & project
$> gcloud info | grep '\(Google\|Account\|Project\)'
Google Cloud SDK [315.0.0]
Account: [None]
Project: [None]
# Initialize
$> gcloud init
Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)? y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&code_challenge=cjLaWdeXW6fY2ux3RITtb4JkOPW477aQsfV_qKhHGDU&code_challenge_method=S256&access_type=offline&response_type=code&prompt=select_account
Enter verification code: *****
You are logged in as: [example.email@gmail.com].
Pick cloud project to use:
[1] kinetic-physics-111111
[2] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 1
Your current project has been set to: [kinetic-physics-293121].
Not setting default zone/region (this feature makes it easier to use
[gcloud compute] by setting an appropriate default value for the
--zone and --region flag).
See https://cloud.google.com/compute/docs/gcloud-compute section on how to set
default compute region and zone manually. If you would like [gcloud init] to be
able to do this for you the next time you run it, make sure the
Compute Engine API is enabled for your project on the
https://console.developers.google.com/apis page.
Created a default .boto configuration file at [/home/vagrant/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!
* Commands that require authentication will use kapitanpiotrek@gmail.com by default
* Commands will reference project `kinetic-physics-293121` by default
Run `gcloud help config` to learn how to change individual settings
This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.
Some things to try next:
* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
Set defaults
# Set project default Compute Engine zone, [17] europe-west1-b $> gcloud config set compute/zone europe-west1-b # Set project default Compute Engine region $> gcloud config set compute/region europe-west1
Install kubectl from Google
$> gcloud components install kubectl ERROR: (gcloud.components.install) You cannot perform this action because the Cloud SDK component manager is disabled for this installation. You can run the following command to achieve the same result for this installation: sudo apt-get install kubectl
Verify
# List accounts whose credentials are stored on the local system:
gcloud auth list
Credentialed Accounts
ACTIVE ACCOUNT
* user1@gmail.com
# List the properties in your active SDK configuration:
gcloud config list
[core]
account = user1@gmail.com
disable_usage_reporting = False
project = responsive-sun-123456
# List multiple so called 'named configurations'
gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT DEFAULT_ZONE DEFAULT_REGION
default True user1@gmail.com responsive-sun-123456 europe-west1-b europe-west1
# View information about your Cloud SDK installation and the active SDK configuration:
gcloud info
Google Cloud SDK [253.0.0]
...
# Verify gcloud project context
$ gcloud info | grep '\(Google\|Account\|Project\)'
Google Cloud SDK [277.0.0]
Account: [user1@gmail.com]
Project: [kinetic-physics-111111]
Cheatsheet
$> gcloud container clusters get-credentials mycluster $> kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system kube-dns-6cd7bbdf65-85nz5 4/4 Running 0 4m38s kube-system kube-dns-6cd7bbdf65-ffrtl 4/4 Running 0 4m12s kube-system kube-dns-autoscaler-bb58c6784-5bx65 1/1 Running 0 4m16s kube-system kube-proxy-gke-cluster-2-jan2020-default-pool-3e5d4a20-ctdg 1/1 Running 0 4m26s kube-system kube-proxy-gke-cluster-2-jan2020-default-pool-3e5d4a20-d2d8 1/1 Running 0 4m24s kube-system kube-proxy-gke-cluster-2-jan2020-default-pool-3e5d4a20-vn76 1/1 Running 0 4m30s kube-system metrics-server-v0.3.1-57c75779f-ctz4h 2/2 Running 0 4m9s Delete default limits $> kubectl delete limits limits
References
- quickstart-debian-ubuntu Google Docs
- Google_GKE