Gcloud SDK 初體驗

[文章目录]
  1. 初體驗
    1. 安裝筆記
    2. 版本資訊
    3. 初始化動作
    4. gcloud 更新紀錄
  2. gcloud 使用範例
  3. 用 gcloud 連結到 GKE 叢集

初體驗

這是我在 MacOS 環境下,進行下載與安裝 gcloud 過程筆記
參考官方文件說明頁

安裝筆記

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
[afu@MacBook-Pro ~/google-cloud-sdk $] ll
total 696
-rw-r--r--@ 1 afu staff 980B 9 25 02:42 LICENSE
-rw-r--r--@ 1 afu staff 673B 9 25 02:42 README
-rw-r--r--@ 1 afu staff 299K 9 25 02:42 RELEASE_NOTES
-rw-r--r--@ 1 afu staff 8B 9 25 02:42 VERSION
drwxr-xr-x@ 11 afu staff 352B 9 25 02:42 bin
-rw-r--r--@ 1 afu staff 2.6K 9 25 02:42 completion.bash.inc
-rw-r--r--@ 1 afu staff 2.0K 9 25 02:42 completion.zsh.inc
drwxr-xr-x@ 3 afu staff 96B 9 25 02:42 data
drwxr-xr-x@ 3 afu staff 96B 9 25 02:47 deb
-rwxr-xr-x@ 1 afu staff 2.0K 9 25 02:42 install.bat
-rwxr-xr-x@ 1 afu staff 4.4K 9 25 02:42 install.sh
drwxr-xr-x@ 7 afu staff 224B 9 25 02:42 lib
-rw-r--r--@ 1 afu staff 377B 9 25 02:42 path.bash.inc
-rw-r--r--@ 1 afu staff 1.2K 9 25 02:42 path.fish.inc
-rw-r--r--@ 1 afu staff 31B 9 25 02:42 path.zsh.inc
drwxr-xr-x@ 5 afu staff 160B 9 25 02:47 platform
-rw-r--r--@ 1 afu staff 39B 9 25 02:47 properties
drwxr-xr-x@ 3 afu staff 96B 9 25 02:47 rpm
[afu@MacBook-Pro ~/google-cloud-sdk $] less install.sh
[afu@MacBook-Pro ~/google-cloud-sdk $]

✘[afu@MacBook-Pro ~/google-cloud-sdk $] ./install.sh
Welcome to the Google Cloud SDK!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:

gcloud config set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)? Y


Your current Cloud SDK version is: 218.0.0
The latest available version is: 230.0.0

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool │ bq │ < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries │ core │ 9.3 MiB │
│ Update Available │ Cloud Storage Command Line Tool │ gsutil │ 3.6 MiB │
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 56.4 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 6.3 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 5.6 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 18.3 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
│ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 32.2 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 33.4 MiB │
│ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 3.7 MiB │
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
│ Not Installed │ Google Cloud Build Local Builder │ cloud-build-local │ 5.9 MiB │
│ Not Installed │ Google Container Registry s Docker credential helper │ docker-credential-gcr │ 1.8 MiB │
│ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
│ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
│ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 107.5 MiB │
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.2 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 28.5 MiB │
│ Not Installed │ kubectl │ kubectl │ < 1 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [218.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [230.0.0], run:
$ gcloud components update


Modify profile to update your $PATH and enable shell command
completion?

Do you want to continue (Y/n)? Y

The Google Cloud SDK installer will now prompt you to update an rc
file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use
[/Users/afu/.zshrc]:
Backing up [/Users/afu/.zshrc] to [/Users/afu/.zshrc.backup].
[/Users/afu/.zshrc] has been updated.

==> Start a new shell for the changes to take effect.


For more information on how to get started, please visit:
https://cloud.google.com/sdk/docs/quickstarts


[afu@MacBook-Pro ~/google-cloud-sdk $]

版本資訊

1
2
3
4
5
6
[afu@MacBook-Pro ~/google-cloud-sdk $] gcloud -v
Google Cloud SDK 218.0.0
bq 2.0.34
core 2018.09.24
gsutil 4.34
[afu@MacBook-Pro ~/google-cloud-sdk $]

初始化動作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
[afu@MacBook-Pro ~/google-cloud-sdk $] 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 (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://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&response_type=code&client_id=32555940559.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




Updates are available for some Cloud SDK components. To install them,
please run:
$ gcloud components update

You are logged in as: [afu at gmail.com].

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

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
# ~~~~~~~~~~~~
# ~~~~~~~~~~~~
[48] europe-north1-b
[49] europe-north1-c
[50] northamerica-northeast1-a
Did not print [6] options.
Too many options [56]. 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/afu/.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 afu at gmail.com by default
* Commands will reference project `integral-plexus-123456` 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 -h` to learn about advanced features of the SDK like arg files and output formatting
[afu@MacBook-Pro ~/google-cloud-sdk $]

gcloud 更新紀錄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[afu@MacBook-Pro ~/google-cloud-sdk $] gcloud components update
Do you want to continue (Y/n)? Y

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: BigQuery Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Cloud SDK Core Libraries ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Cloud Storage Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: gcloud cli dependencies ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: BigQuery Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Cloud SDK Core Libraries ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Cloud Storage Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud cli dependencies ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!

To revert your SDK to the previously installed version, you may run:
$ gcloud components update --version 218.0.0

# 新版本版號資訊
[afu@MacBook-Pro ~/google-cloud-sdk $] gcloud -v
Google Cloud SDK 230.0.0
bq 2.0.39
core 2019.01.11
gsutil 4.35
[afu@MacBook-Pro ~/google-cloud-sdk $]

gcloud 使用範例

1
2
3
4
5
6
7
# 設定預設區域
$ gcloud config set compute/zone asia-east1-a
Updated property [compute/zone].

# 取得特定資訊
$ gcloud config get-value compute/zone
asia-east1-a

用 gcloud 連結到 GKE 叢集

事前條件:已經於 GKE 上完成創建叢集環境,於GKE 介面上複製下列指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 執行
[afu@MacBook-Pro ~/google-cloud-sdk $] gcloud container clusters get-credentials afu-first-cluster-1 --zone asia-east1-a --project integral-plexus-123456

Fetching cluster endpoint and auth data.
kubeconfig entry generated for afu-first-cluster-1.

# 查看 kube/config
# 會發現新增 cluster、context 資訊,與異動後的 current-context
[afu@MacBook-Pro ~/google-cloud-sdk $] less ~/.kube/config

[afu@MacBook-Pro ~/google-cloud-sdk $] kc get nodes
NAME STATUS ROLES AGE VERSION
gke-afu-first-cluster-1-pool-1-dd90def6-lrcb Ready <none> 1h v1.11.6-gke.2
[afu@MacBook-Pro ~/google-cloud-sdk $]