網頁

2023/2/9

GCP gcloud CLI 初始化

GCP gcloud CLI安裝後要先初始化設定操作GCP的權限。


範例環境:

  • Google Cloud SDK 417.0.1


初始化

在終端機輸入gcloud init進行gcloud CLI的初始化設定。

% 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

Your browser has been opened to visit:

    https://<log_in_and_grant_access_page_url>

輸入後會要求登入並在瀏覽器開啟登入及授權頁面,點選[允許]。



接著選擇操作的project ID(在GCP console查看)及預設的區域(Region and Zone),例如asia-east1-b

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

Pick cloud project to use:
 [1] <projct-id-1>
 [2] <projct-id-2>
 [3] <projct-id-3>
 [4] Enter a project ID
 [5] Create a new project
Please enter numeric choice or text value (must exactly match list item):  1

Your current project has been set to: [<projct-id-1>].

Do you want to configure a default Compute Region and Zone? (Y/n)?  Y

Which Google Compute Engine zone would you like to use as project default?
If you do not specify a zone via a command line flag while working with Compute Engine resources, the default is assumed.
 [1] us-east1-b
 [2] us-east1-c
 [3] us-east1-d
...
 [26] asia-east1-b
 [27] asia-east1-a
 [28] asia-east1-c
...
 [50] asia-northeast3-a
Did not print [57] options.
Too many options [107]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list item):  26

Your project default Compute Engine zone has been set to [asia-east1-b].
You can change it by running [gcloud config set compute/zone NAME].

Your project default Compute Engine region has been set to [asia-east1].
You can change it by running [gcloud config set compute/region NAME].

Created a default .boto configuration file at [/Users/<user>/.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 &t;youraccount>@gmail.com by default
* Commands will reference project `<projct-id-1>` by default
* Compute Engine commands will use region `asia-east1` by default
* Compute Engine commands will use zone `asia-east1-b` 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
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.

完成以上即可開始用gcloud CLI對GCP資源進行操作。

初始化後會在使用者目錄/User/<user><user>為macOS帳戶名稱)下建立名為.boto的配置檔。


沒有留言:

張貼留言