mac OS Sonoma に gcloud CLI を導入する
概要
- 以前 Windows 11 で行った gcloud CLI の導入を、macOS でも実施する
- 前回はプロジェクトの作成まで行ったが、今回は
gcloud --version
の動作を確認するところまでをゴールとする
参照したリファレンス
作業ログ
※2024年4月に実施した内容です。後追いで記事化しているため公開日とラグがあります。
Python のバージョンを確認
サポートされているバージョンは Python 3.8~3.12 です。
前述のリファレンスに上記の指定があるため、バージョンを確認する。
> python -V
Python 2.7.18
> python3 -V
Python 3.9.6
python3 のほうを使えばOK
パッケージをダウンロード
チップが Apple M3 Pro
のマシンを使っているので、以下のパッケージが該当。
項目 | 内容 |
---|---|
プラットフォーム | macOS 64 ビット(ARM64, Apple M1 silicon) |
パッケージ | google-cloud-cli-470.0.0-darwin-arm.tar.gz |
SHA256 チェックサム | e92d9af260ef28300ed2d5c30a4871fe1cac3f44dac823a358c52b11b56dd058 |
wget でダウンロード後、任意で展開する。今回は ~/Applications
の中にした
> wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-470.0.0-darwin-arm.tar.gz -O - | tar xvf - -C ~/Applications/
入ったことを確認
> ls -la ~/Applications | grep google
drwxr-xr-x 21 ユーザー名 staff 672 4 12 15:30 google-cloud-sdk
インストールスクリプトを実行
インストールした場所へ移動
> cd ~/Applications
インストールスクリプトを実行し、指示に従って設定を進める
> google-cloud-sdk/install.sh
Welcome to the Google Cloud CLI!
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>. This data is
handled in accordance with our privacy policy
<https://cloud.google.com/terms/cloud-privacy-notice>. You may choose to opt in this
collection now (by choosing 'Y' at the below prompt), or at any time in the
future by running the following command:
gcloud config set disable_usage_reporting false
Do you want to help improve the Google Cloud CLI (y/N)? y
Your current Google Cloud CLI version is: 470.0.0
The latest available version is: 471.0.0
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool │ bq │ 1.7 MiB │
│ Update Available │ Google Cloud CLI Core Libraries │ core │ 18.3 MiB │
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 4.5 MiB │
│ Not Installed │ Appctl │ appctl │ 18.5 MiB │
│ Not Installed │ Artifact Registry Go Module Package Helper │ package-go-module │ < 1 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 16.7 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 7.0 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 36.2 MiB │
│ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 44.5 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 63.3 MiB │
│ Not Installed │ Cloud Run Proxy │ cloud-run-proxy │ 11.3 MiB │
│ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 7.3 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ │
│ Not Installed │ Kustomize │ kustomize │ 7.4 MiB │
│ Not Installed │ Log Streaming │ log-streaming │ 11.9 MiB │
│ Not Installed │ Minikube │ minikube │ 33.6 MiB │
│ Not Installed │ Nomos CLI │ nomos │ 28.6 MiB │
│ Not Installed │ On-Demand Scanning API extraction helper │ local-extract │ 13.7 MiB │
│ Not Installed │ Skaffold │ skaffold │ 23.3 MiB │
│ Not Installed │ Terraform Tools │ terraform-tools │ 63.6 MiB │
│ Not Installed │ anthos-auth │ anthos-auth │ 20.7 MiB │
│ Not Installed │ config-connector │ config-connector │ 55.6 MiB │
│ Not Installed │ enterprise-certificate-proxy │ enterprise-certificate-proxy │ 8.3 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 │ 126.2 MiB │
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 5.0 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ < 1 MiB │
│ Not Installed │ gke-gcloud-auth-plugin │ gke-gcloud-auth-plugin │ 7.4 MiB │
│ Not Installed │ kpt │ kpt │ 14.4 MiB │
│ Not Installed │ kubectl │ kubectl │ < 1 MiB │
│ Not Installed │ kubectl-oidc │ kubectl-oidc │ 20.7 MiB │
│ Not Installed │ pkg │ pkg │ │
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 11.3 MiB │
│ Installed │ Google Cloud CRC32C Hash Tool │ gcloud-crc32c │ 1.2 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────────┴───────────┘
To install or remove components at your current SDK version [470.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
To update your SDK installation to the latest version [471.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/ユーザー名/.zshrc]:
Backing up [/Users/ユーザー名/.zshrc] to [/Users/ユーザー名/.zshrc.backup].
[/Users/ユーザー名/.zshrc] has been updated.
==> Start a new shell for the changes to take effect.
Google Cloud CLI works best with Python 3.11 and certain modules.
Download and run Python 3.11 installer? (Y/n)? n
For more information on how to get started, please visit:
https://cloud.google.com/sdk/docs/quickstarts
.zshrc
を確認すると、末尾にPATHの設定が追記されていた
> cat ~/.zshrc
〜省略〜
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/ユーザー名/Applications/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/ユーザー名/Applications/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/ユーザー名/Applications/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/ユーザー名/Applications/google-cloud-sdk/completion.zsh.inc'; fi
Python を推奨バージョンに切替
Python のバージョン管理は、Homebrew 経由で落とした pyenv で行っている
Google Cloud CLU は 3.11 が推奨バージョンみたいなので、これをデフォルトにしておく
Homebrew を最新化
> brew update
==> Updating Homebrew...
Already up-to-date.
pyenv が最新版であることを確認
> pyenv --version
pyenv 2.4.0
現在の global バージョンを確認 → 2.7.18 になってる
> pyenv global
2.7.18
3.11 系の最新バージョンを確認 → 3.11.9 みたい
> pyenv install --list | grep 3.11
3.11.0
3.11-dev
3.11.1
3.11.2
3.11.3
3.11.4
3.11.5
3.11.6
3.11.7
3.11.8
3.11.9
3.11.9 をインストール
> pyenv install 3.11.9
python-build: use openssl@3 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.9.tar.xz...
-> https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tar.xz
Installing Python-3.11.9...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.11.9 to /Users/ユーザー名/.pyenv/versions/3.11.9
3.11.9 をグローバルに設定 → 確認OK
> pyenv global 3.11.9
> pyenv global
3.11.9
gcloud CLI を初期化
> google-cloud-sdk/bin/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://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&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%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=e020FP03eSWYRQrjD2BfP1KbYGmUCN&access_type=offline&code_challenge=JViDLeKu83AZgpU0gt98p2M947XnNS_pb1zJVhhhqwk&code_challenge_method=S256
ブラウザが立ち上がり、ログイン認証画面が開く
アカウントを選択
[次へ] をクリック
[許可] をクリック
完了ページへ遷移する
https://cloud.google.com/sdk/auth_success?hl=ja
Terminal に戻ると、以下が出力されていた。プロジェクトの作成はせず終了。
Updates are available for some Google Cloud CLI components. To install them,
please run:
$ gcloud components update
You are logged in as: [Googleアカウントのメールアドレス].
This account has no projects.
Would you like to create one? (Y/n)? n
動作チェック
gcloud のバージョンを表示 → 成功。ここでもコンポーネントのアプデを勧められる。
> gcloud --version ok | 8s | system node | gcloud | 16:03:16
Google Cloud SDK 470.0.0
bq 2.1.2
core 2024.03.22
gcloud-crc32c 1.0.0
gsutil 5.27
Updates are available for some Google Cloud CLI components. To install them,
please run:
$ gcloud components update
コンポーネントをアップデート
案内されたコマンドを叩く。
> gcloud components update ok | system node | gcloud | 16:03:55
Beginning update. This process may take several minutes.
Your current Google Cloud CLI version is: 470.0.0
You will be upgraded to version: 471.0.0
┌─────────────────────────────────────────────────────────┐
│ These components will be updated. │
├─────────────────────────────────┬────────────┬──────────┤
│ Name │ Version │ Size │
├─────────────────────────────────┼────────────┼──────────┤
│ BigQuery Command Line Tool │ 2.1.3 │ 1.7 MiB │
│ Google Cloud CLI Core Libraries │ 2024.03.29 │ 18.3 MiB │
│ gcloud cli dependencies │ 2024.03.29 │ 16.6 MiB │
└─────────────────────────────────┴────────────┴──────────┘
┌────────────────────────────────────────────────┐
│ These components will be installed. │
├─────────────────────────┬────────────┬─────────┤
│ Name │ Version │ Size │
├─────────────────────────┼────────────┼─────────┤
│ gcloud cli dependencies │ 2021.04.16 │ < 1 MiB │
└─────────────────────────┴────────────┴─────────┘
The following release notes are new in this upgrade.
Please read carefully for information about new features, breaking changes,
and bugs fixed. The latest full release notes can be viewed at:
https://cloud.google.com/sdk/release_notes
471.0.0 (2024-04-02)
AI
▪ Modified --region flag of gcloud ai endpoints to include new online
prediction regions.
▪ Modified --region flag of gcloud ai models to include new online
prediction regions.
AlloyDB
▪ Added flag --assign-inbound-public-ip to enable or disable public IP
for an instance to the following commands in the GA track:
◆ gcloud alloydb instances create
◆ gcloud alloydb instances update
▪ Added flag --authorized-external-networks to set a list of authorized
external networks on an instance to gcloud alloydb instances update in
the GA track.
App Engine
▪ Updated the Java SDK to version 2.0.26 build from the open source
project
<https://github.com/GoogleCloudPlatform/appengine-java-standard/releases/tag/v2.0.26>.
BigQuery
▪ Downgraded urllib3 to version 1.26.9 be compatible with the request
lib.
Certificate Authority Service
▪ Added Subject Key Id field to arguments gcloud privateca roots create
to allow usage of a custom subject key id for root certificate
authorities.
▪ Added Subject Key Id field to arguments gcloud privateca subordinates
create to allow usage of a custom subject key id for subordinate
certificate authorities.
▪ Added Subject Key Id field to arguments gcloud privateca certificates
create to allow usage of a custom subject key id for certificates.
▪ Added maximum lifetime argument to gcloud privateca templates create
to allow configuring maximum lifetime restriction using certificate
templates.
Certificate Manager
▪ Added allowlistedCertificates property to certificate-manager
trust-configs import and certificate-manager trust-configs export.
Cloud Bigtable
▪ Rebuilt cbt cli with google.golang.org/protobuf version 1.33.0 which
fixed CVE-2024-24786.
Cloud Bigtable Emulator
▪ Rebuilt cbt cli with google.golang.org/protobuf version 1.33.0 which
fixed CVE-2024-24786.
Cloud Composer
▪ Added gcloud beta composer environments list-workloads to display
Composer workloads list.
▪ Added gcloud beta composer environments user-workloads-config-maps
create to create a user workloads ConfigMap.
▪ Added gcloud beta composer environments user-workloads-config-maps
delete to delete a user workloads ConfigMap.
▪ Added gcloud beta composer environments user-workloads-config-maps
describe to get details about a user workloads ConfigMap.
▪ Added gcloud beta composer environments user-workloads-config-maps
list to list user workloads ConfigMaps.
▪ Added gcloud beta composer environments user-workloads-config-maps
update to update a user workloads ConfigMap.
▪ Added gcloud beta composer environments user-workloads-secrets create
to create a user workloads Secret.
▪ Added gcloud beta composer environments user-workloads-secrets delete
to delete a user workloads Secret.
▪ Added gcloud beta composer environments user-workloads-secrets
describe to get details about a user workloads Secret.
▪ Added gcloud beta composer environments user-workloads-secrets list
to list user user workloads Secrets.
▪ Added gcloud beta composer environments user-workloads-secrets update
to update a user workloads Secret.
Cloud Deploy
▪ Updated gcloud deploy apply to accept the Automation resource YAML
configuration with the field names in the API proto.
Cloud Infrastructure Manager
▪ Added --file flag to gcloud infra-manager deployments
export-statefile to download statefile with a custom file name/path or
by default to a file named statefile if only file path is provided.
Cloud Memorystore
▪ Add --node-type flag to redis clusters create to add the ability to
create clusters with different node types.
Cloud NetApp
▪ Added --backup-config and --source-backup to gcloud netapp volumes to
allow scheduled backups and create volume from backup workflow.
Cloud Pub/Sub
▪ Promoted --cloud-storage-file-datetime-format flag of gcloud pubsub
subscriptions create to GA. Added the ability to set custom Cloud
Storage filename datetimes in Cloud Pub/Sub to Cloud Storage
subscriptions. For more information, see
<https://cloud.google.com/pubsub/docs/create-cloudstorage-subscription#file_names>.
▪ Promoted --cloud-storage-file-datetime-format flag of gcloud pubsub
subscriptions update to GA. Added the ability to update custom Cloud
Storage filename datetimes in Cloud Pub/Sub to Cloud Storage
subscriptions. For more information, see
<https://cloud.google.com/pubsub/docs/create-cloudstorage-subscription#file_names>.
Cloud Run
▪ Updated integration name generation logic to use the integration type
followed by 4 digit hash.
Cloud SQL
▪ Support for designating a disaster recovery replica in gcloud sql
instances patch command using --failover-dr-replica-name flag is in
beta.
Compute Engine
▪ Added gcloud compute storage-pools and gcloud compute
storage-pools-types command groups which can read Compute storage pools
and storage pool types. Documentation of the storage pools will be
available at
<https://cloud.google.com/compute/docs/disks/storage-pools>.
Compute OS Config
▪ Added gcloud compute os-config project-feature-settings commands that
allow to view and change the project feature settings.
Database Migration
▪ Added gcloud database-migrate connection-profiles create sqlserver
which creates a Database Migration Service connection profile for SQL
Server.
▪ Updated gcloud database-migrate migration-jobs create to create
Database Migration Service migration job for SQL Server to Cloud
SQL-SQL Server migrations.
▪ Added --dump-type to gcloud database-migrate migration-jobs create to
allow creating a migration job with PHYSICAL or LOGICAL dump type.
▪ Added --dump-type to gcloud database-migrate migration-jobs update to
allow updating a migration job with PHYSICAL or LOGICAL dump type.
GKE Hub
▪ Updated gcloud container fleet scopes list to return Fleet Scopes
permitted to be viewed by the caller.
▪ Added gcloud container fleet scopes list-memberships SCOPE to return
Fleet Memberships bound to SCOPE.
Kubernetes Engine
▪ Added --additive-vpc-scope-dns-domain and
--disable-additive-vpc-scope flags to gcloud container clusters create,
create-auto and update.
▪ Added --security-posture=enterprise flag to gcloud container clusters
create, gcloud container clusters create-auto, and gcloud container
clusters update to enable GKE Threat Detection.
Regional Endpoints
▪ Add optional address input flag to gcloud beta networkconnectivity
regional-endpoints create.
Workbench
▪ Fixed issue with gcloud workbench instances failing when
accelerator-type flag is set to NVIDIA_A100_80GB.
Subscribe to these release notes at
https://groups.google.com/forum/#!forum/google-cloud-sdk-announce
(https://groups.google.com/forum/#!forum/google-cloud-sdk-announce).
Do you want to continue (Y/n)? Y
╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: BigQuery Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Google Cloud CLI Core Libraries ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: gcloud cli dependencies ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: BigQuery Command Line Tool ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Google Cloud CLI Core Libraries ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud cli dependencies ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud cli dependencies ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation ═╣
╚════════════════════════════════════════════════════════════╝
Performing post processing steps...done.
Update done!
To revert your CLI to the previously installed version, you may run:
$ gcloud components update --version 470.0.0
再度バージョンを確認 → 最新の 471.0.0 になった。これにて完了。
> gcloud --version ok | 2m 57s | system node | gcloud | 16:12:19
Google Cloud SDK 471.0.0
bq 2.1.3
core 2024.03.29
gcloud-crc32c 1.0.0
gsutil 5.27