gcloud installation on Mac, SSH Connection with VSCode

Page content

개요

Screenshot 2024-04-22 at 6.15.48 PM.png

설치파일 다운로드

  • 각 사용자 버전에 맞는 설치 파일을 다운로드 받는다.
    • 필자는 M1 silicon 버전을 사용하기로 하였다.
    • Desktop > gcloud_install 내부에 해당 파일을 다운로드 받았다.

Screenshot 2024-04-22 at 6.16.45 PM.png

  • 압축을 풀면 아래와 같이 google-cloud-sdk 폴더 안애 install.sh 파일이 있다.

Screenshot 2024-04-22 at 6.20.54 PM.png

설치파일 실행

  • 해당 폴더에 있는 파일에 접속해서 install.sh 파일을 실행한다.
$ {your_location}/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: 471.0.0
The latest available version is: 472.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.4 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.8 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 v2                                   │ cloud-sql-proxy              │  13.2 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                     │  22.8 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 [471.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [472.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/evan/.bash_profile]:  
Backing up [/Users/evan/.bash_profile] to [/Users/evan/.bash_profile.backup].
[/Users/evan/.bash_profile] 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)?  Y
Running Python 3.11 installer, you may be prompted for sudo password...
Password: # your_password
installer: Package name is Python
installer: Upgrading at base path /
installer: The upgrade was successful.
Setting up virtual environment
Creating virtualenv...
Installing modules...
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.7/89.7 kB 4.6 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 59.0/59.0 kB 5.9 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.0/10.0 MB 33.9 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.8/163.8 kB 16.1 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.3/5.3 MB 42.0 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 176.7/176.7 kB 15.4 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.6/117.6 kB 10.4 MB/s eta 0:00:00
  Building wheel for crcmod (pyproject.toml) ... done

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

Virtual env enabled.

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts
  • gcloud CLI를 초기화하려면 gcloud init 을 실행한다.
$ ./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/....S256

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

Pick cloud project to use: 
 [1] chickenbot-a185e
 [2] encoded-phalanx-420600
 [3] streamlit-gitaction-403105
 [4] streamlit-project-416601
 [5] Enter a project ID
 [6] Create a new project
Please enter numeric choice or text value (must exactly match list item):  2

Screenshot 2024-04-22 at 6.34.04 PM.png

  • 계속해서 터미널에 질문이 나온다.
Your current project has been set to: [encoded-phalanx-420600].

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
 [4] us-east4-c
 [5] us-east4-b
 [6] us-east4-a
 [7] us-central1-c
 [8] us-central1-a
 [9] us-central1-f
 [10] us-central1-b
 [11] us-west1-b
 [12] us-west1-c
 [13] us-west1-a
 [14] europe-west4-a
 [15] europe-west4-b
 [16] europe-west4-c
 [17] europe-west1-b
 [18] europe-west1-d
 [19] europe-west1-c
 [20] europe-west3-c
 [21] europe-west3-a
 [22] europe-west3-b
 [23] europe-west2-c
 [24] europe-west2-b
 [25] europe-west2-a
 [26] asia-east1-b
 [27] asia-east1-a
 [28] asia-east1-c
 [29] asia-southeast1-b
 [30] asia-southeast1-a
 [31] asia-southeast1-c
 [32] asia-northeast1-b
 [33] asia-northeast1-c
 [34] asia-northeast1-a
 [35] asia-south1-c
 [36] asia-south1-b
 [37] asia-south1-a
 [38] australia-southeast1-b
 [39] australia-southeast1-c
 [40] australia-southeast1-a
 [41] southamerica-east1-b
 [42] southamerica-east1-c
 [43] southamerica-east1-a
 [44] africa-south1-a
 [45] africa-south1-b
 [46] africa-south1-c
 [47] asia-east2-a
 [48] asia-east2-b
 [49] asia-east2-c
 [50] asia-northeast2-a
Did not print [72] options.
Too many options [122]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list item):  53
Your project default Compute Engine zone has been set to [asia-northeast3-a].
You can change it by running [gcloud config set compute/zone NAME].

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

Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use j2hoon85@gmail.com by default
* Commands will reference project `encoded-phalanx-420600` by default
* Compute Engine commands will use region `asia-northeast3` by default
* Compute Engine commands will use zone `asia-northeast3-a` 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.

GCP 프로젝트 다운로드

  • 기존에 진행하던 GCP 프로젝트를 다운로드 받는다.
git clone your@github.com/your_name/your_repo.git
  • VS Code로 열고 터미널을 연 상태에서 진행한다.
    • 필자의 Mac 화면은 아래와 같다.

Screenshot 2024-04-22 at 7.01.09 PM.png

  • 이 상황에서 Extension 메뉴를 선택하고 Remote-SSH를 설치한다.

Screenshot 2024-04-22 at 7.03.51 PM.png

SSH 키 값 생성

  • RSA Key Pair를 생성한다. (Google Cloud Account)
ssh-keygen -t rsa -C "your google account"
  • cat 명령어를 활용하여 id_rsa.pub 키 값을 출력하고 복사한다.
$ cat ~/.ssh/id_rsa.pub
ssh-rsa A...+x4LC3oU= your@gmail.com

GCE 메타데이터 등록

  • 복사한 키값을 메타데이터-SSH에 등록하도록 한다.

Screenshot 2024-04-22 at 7.14.18 PM.png

Remote SSH 실행

  • 아래와 같이 SSH Connection Command 창에서 아래 명령어를 실행한다.

Screenshot 2024-04-22 at 7.22.47 PM.png

ssh username@external_ip # 예: ssh yourname@34.64.174.182

Screenshot 2024-04-22 at 7.20.42 PM.png

  • 우측 하단에 아래 화면에서 Connect 버튼을 선택한다.

Screenshot 2024-04-22 at 7.23.43 PM.png

  • 아래화면에서 Continue 버튼을 클릭한다.

Screenshot 2024-04-22 at 7.24.48 PM.png

GCP 터미널 접속

  • 이제 아래 화면에서 실제 접속이 된 것을 확인한다.

Screenshot 2024-04-22 at 7.27.22 PM.png