Actions

Difference between revisions of "GCP/gcloud cli"

From Ever changing code

< GCP
(Created page with "Install <code>gcloud</code> cli <source lang=bash> # Add the Cloud SDK distribution URI as a package source echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://p...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Install <code>gcloud</code> cli
+
= Install <code>gcloud</code> cli =
 
<source lang=bash>
 
<source lang=bash>
 
# Add the Cloud SDK distribution URI as a package source
 
# Add the Cloud SDK distribution URI as a package source
Line 11: Line 11:
 
</source>
 
</source>
  
Initialize
+
= Initialize =
 
<source lang=bash>
 
<source lang=bash>
 
$ gcloud init
 
$ gcloud init
Line 63: Line 63:
 
Your Google Cloud SDK is configured and ready to use!
 
Your Google Cloud SDK is configured and ready to use!
  
* Commands that require authentication will use piotr.pawlak100@gmail.com by default
+
* Commands that require authentication will use example.email@gmail.com by default
* Commands will reference project `responsive-sun-246311` by default
+
* Commands will reference project `responsive-sun-123456` by default
 
Run `gcloud help config` to learn how to change individual settings
 
Run `gcloud help config` to learn how to change individual settings
  
Line 74: Line 74:
 
* 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 --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
 
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
 +
</source>
 +
 +
= Verify =
 +
<source lang=bash>
 +
#To list accounts whose credentials are stored on the local system:
 +
gcloud auth list
 +
      Credentialed Accounts
 +
ACTIVE            ACCOUNT
 +
*                  example-user-1@gmail.com
 +
 +
#To list the properties in your active SDK configuration:
 +
gcloud config list
 +
[core]
 +
account = example-user-1@gmail.com
 +
disable_usage_reporting = False
 +
project = example-project
 +
 +
#To view information about your Cloud SDK installation and the active SDK configuration:
 +
gcloud info
 +
Google Cloud SDK [253.0.0]
 +
 +
Platform: [Linux, x86_64] ('Linux', 'u18gui-2', '4.15.0-54-generic', '#58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019', 'x86_64', 'x86_64')
 +
Locale: ('en_US', 'UTF-8')
 +
Python Version: [2.7.15+ (default, Nov 27 2018, 23:36:35)  [GCC 7.3.0]]
 +
Python Location: [/usr/bin/python2]
 +
Site Packages: [Disabled]
 +
 +
Installation Root: [/usr/lib/google-cloud-sdk]
 +
Installed Components:
 +
  kubectl: [2019.06.28]
 +
  core: [2019.06.28]
 +
  beta: [2019.06.28]
 +
  gsutil: [4.39]
 +
  bq: [2.0.44]
 +
  alpha: [2019.06.28]
 +
System PATH: [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
 +
Python PATH: [/usr/bin/../lib/google-cloud-sdk/lib/third_party:/usr/lib/google-cloud-sdk/lib:/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload]
 +
Cloud SDK on PATH: [False]
 +
Kubectl on PATH: [False]
 +
 +
Installation Properties: [/usr/lib/google-cloud-sdk/properties]
 +
User Config Directory: [/home/vagrant/.config/gcloud]
 +
Active Configuration Name: [default]
 +
Active Configuration Path: [/home/vagrant/.config/gcloud/configurations/config_default]
 +
 +
Account: [example.user@gmail.com]
 +
Project: [responsive-sun-123456]
 +
 +
Current Properties:
 +
  [core]
 +
    project: [responsive-sun-123456]
 +
    account: [example.user@gmail.com]
 +
    disable_usage_reporting: [True]
 +
 +
Logs Directory: [/home/vagrant/.config/gcloud/logs]
 +
Last Log File: [/home/vagrant/.config/gcloud/logs/2019.07.10/13.01.21.321193.log]
 +
 +
git: [git version 2.17.1]
 +
ssh: [OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017]
 
</source>
 
</source>
  
 
= References =  
 
= References =  
 
* [https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu quickstart-debian-ubuntu] Google Docs
 
* [https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu quickstart-debian-ubuntu] Google Docs

Latest revision as of 15:22, 10 July 2019

Install gcloud cli

# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://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

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?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_account&response_type=code&client_id=12345678901.apps.googleusercontent.com&scope=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&access_type=offline


Enter verification code: *****


To take a quick anonymous survey, run:
  $ gcloud alpha survey

You are logged in as: [example.email@gmail.com].

Pick cloud project to use: 
 [1] responsive-sun-123456
 [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: [responsive-sun-123456].

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 example.email@gmail.com by default
* Commands will reference project `responsive-sun-123456` 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

Verify

#To list accounts whose credentials are stored on the local system:
gcloud auth list
       Credentialed Accounts
ACTIVE             ACCOUNT
*                  example-user-1@gmail.com

#To list the properties in your active SDK configuration:
gcloud config list
[core]
account = example-user-1@gmail.com
disable_usage_reporting = False
project = example-project

#To view information about your Cloud SDK installation and the active SDK configuration:
gcloud info
Google Cloud SDK [253.0.0]

Platform: [Linux, x86_64] ('Linux', 'u18gui-2', '4.15.0-54-generic', '#58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019', 'x86_64', 'x86_64')
Locale: ('en_US', 'UTF-8')
Python Version: [2.7.15+ (default, Nov 27 2018, 23:36:35)  [GCC 7.3.0]]
Python Location: [/usr/bin/python2]
Site Packages: [Disabled]

Installation Root: [/usr/lib/google-cloud-sdk]
Installed Components:
  kubectl: [2019.06.28]
  core: [2019.06.28]
  beta: [2019.06.28]
  gsutil: [4.39]
  bq: [2.0.44]
  alpha: [2019.06.28]
System PATH: [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
Python PATH: [/usr/bin/../lib/google-cloud-sdk/lib/third_party:/usr/lib/google-cloud-sdk/lib:/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload]
Cloud SDK on PATH: [False]
Kubectl on PATH: [False]

Installation Properties: [/usr/lib/google-cloud-sdk/properties]
User Config Directory: [/home/vagrant/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/home/vagrant/.config/gcloud/configurations/config_default]

Account: [example.user@gmail.com]
Project: [responsive-sun-123456]

Current Properties:
  [core]
    project: [responsive-sun-123456]
    account: [example.user@gmail.com]
    disable_usage_reporting: [True]

Logs Directory: [/home/vagrant/.config/gcloud/logs]
Last Log File: [/home/vagrant/.config/gcloud/logs/2019.07.10/13.01.21.321193.log]

git: [git version 2.17.1]
ssh: [OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017]

References