Cloud SDKをインストール
まずはローカルにCloud SDKをインストールする必要があります。
Python 2.7 が入っているかを確認します
python -V
下記から自分の環境にあったソースコードをダウンロード
https://cloud.google.com/sdk/downloads
展開した後に下記を実行
./google-cloud-sdk/install.sh
問題なければ、ここで一旦ターミナルを閉じます
その後に下記を実行して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&access_type=offline
You are logged in as: [hogehoge@gmail.com].
Your current project has been set to: [hogehoge].
Do you want to configure Google Compute Engine
(https://cloud.google.com/compute) settings (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] asia-east1-b
[2] asia-east1-a
[3] asia-east1-c
[4] asia-northeast1-a
[5] asia-northeast1-b
[6] asia-northeast1-c
[7] europe-west1-d
[8] europe-west1-c
[9] europe-west1-b
[10] us-central1-b
[11] us-central1-c
[12] us-central1-a
[13] us-central1-f
[14] us-east1-c
[15] us-east1-d
[16] us-east1-b
[17] us-west1-b
[18] us-west1-a
[19] Do not set default zone
Please enter numeric choice or text value (must exactly match list
item): 4
Your project default Compute Engine zone has been set to [asia-northeast1-a].
You can change it by running [gcloud config set compute/zone NAME].
Your project default Compute Engine region has been set to [asia-northeast1].
You can change it by running [gcloud config set compute/region NAME].
Created a default .boto configuration file at [/Users/mydir/.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 hogehoge@gmail.com by default
* Commands will reference project `hogehoge` by default
* Compute Engine commands will use region `asia-northeast1` by default
* Compute Engine commands will use zone `asia-northeast1-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 -h` to learn about advanced features of the SDK like arg files and output formatting
ここまで行けばひとまず初期化は完了です。
Cloud ソース レポジトリを使ってみる
続いてせっかくなので Cloud ソースレポジトリを使ってソースコードを管理してみたいと思います
下記にアクセスして新しいレポジトリを作成します
https://console.cloud.google.com/code/
今回はローカル Git レポジトリへの Cloud レポジトリのクローン作成
をやってみます
https://cloud.google.com/source-repositories/docs/quickstart
※gitはインストール済みでしたが、もし入っていない場合はgcloud init
を行う前にインストールする必要があるようです
作成後案内通りに下記のコマンドを叩いてcloneしてみます
% gcloud source repos clone repo-sample --project=hogehoge
WARNING: You are cloning a Google-hosted repository with a
git version 1.9.1
which is older than 2.0.1. If you upgrade
to 2.0.1 or later, gcloud can handle authentication to
this repository. Otherwise, to authenticate, use your Google
account and the password found by running the following command.
$ gcloud auth print-access-token
Cloning into '/Users/mydir/work/gcloud-repo/repo-sample'...
Username for 'https://source.developers.google.com': hogehoge@gmail.com
Password for 'https://hogehoge@gmail.com@source.developers.google.com':
fatal: remote error:
Invalid authentication credentials.
Please generate a new identifier:
https://source.developers.google.com/auth/start?scopes=https://www.googleapis.com/auth/cloud-platform
ERROR: (gcloud.source.repos.clone) Command '['git', 'clone', 'https://source.developers.google.com/p/hogehoge/r/repo-sample', '/Users/mydir/work/gcloud-repo/repo-sample']' returned non-zero exit status 128
失敗しました。。。
認証に失敗した様子です
案内の通り下記のURLにアクセスすると手順が載っていました
やったことは下記です
- ホームディレクトリの
.netrc
に下記を追加
machine source.developers.google.com login [your email address] password [your password]
- 下記のコマンドでgitのcookieファイルをきれいにする
git config http.cookiefile
再び下記のコマンドを実行した所、うまくいきました
% gcloud source repos clone repo-sample --project=hogehoge
WARNING: You are cloning a Google-hosted repository with a
git version 1.9.1
which is older than 2.0.1. If you upgrade
to 2.0.1 or later, gcloud can handle authentication to
this repository. Otherwise, to authenticate, use your Google
account and the password found by running the following command.
$ gcloud auth print-access-token
Cloning into '/Users/mydir/work/gcloud-repo/repo-sample'...
Checking connectivity... done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
Project [hogehoge] repository [repo-sample] was cloned to [/Users/mydir/work/gcloud-repo/repo-sample].
githubやbitbucketと連携することも出来るようです。
kubernetesを利用する
kubernetesを利用するにはCloud SDKを使うことになるようなのでまずは準備としてインストールしました