LoginSignup
10
10

More than 5 years have passed since last update.

Cloud Code で GKE にアプリケーションをデプロイする方法

Last updated at Posted at 2019-04-13

コンテナアプリ開発に便利な Visual Studio Code と IntelliJ 用のプラグイン Cloud Code で、Google Cloud Kubernetes Engine (GKE) クラスタにアプリケーションをデプロイできるようになりました。ここでは、Visual Studio Code 用を使って、サンプルアプリ Guestbook をデプロイしてみたいと思います。また、コンテナのビルドは Cloud Build を使ってみしょう。

方法は、QuickStart を見ればだいたいわかりますが、日本語でもまとめてみました。

  • QuickStart を参考に、Docker と kubectl と Skaffold を入れておきます。ここでは Mac 環境での準備を参考に書いておきます。ちなみに、Skaffold は Kubernetes クラスタで、アプリケーションの継続的デリバリーを行うコマンドラインツールです。Skaffold を利用するには kubectl と Docker が必要になります。

brew install kubernetes-cli
brew install skaffold
  • Cloud SDK を インストールし、gcloud 環境を初期化
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init
  • GCP コンソールより、 GKE クラスタを構築(Cloud Code を入れると、Cloud Code からも作成できるようです)
    image.png

  • VS Code から、Shift + Command + X で拡張機能ビューを表示して、Cloud Code を検索しインストール
    image.png

  • Shift + Command + P でコマンドパレットを表示して、Cloud Code: New Applicationで、アプリケーションを作成。ここでは、Node.js: Guestbook を選択
    image.png

  • 新しいウインドウで、サンプルアプリのワークスペースがオープン
    image.png

  • GKE クラスタが正しく構築されていると VS Code にこのように表示されます。左のアクティビティバーの下にある Cloud Code のアイコンをクリックすると、Kubernetes 環境が表示されます。
    image.png

  • 作成された、GKE クラスタを右クリックし Set as Active Cluster をクリックし、Active Cluster に設定すると、Cluster Explorer に GKE クラスタが表示されます。

  • Cloud Code: Deploy でサンプルアプリケーションをデプロイ

    • [default] ローカルの Docker 環境でビルド
    • cloudbuild Cloud Build 環境でビルド (今回はこちらを選択)
  • Cloud Build 環境で、コンテナをビルドするときの注意
     + quickstart-docker を参考に、Cloud Build API を有効にしておきましょう。
     + getting google client: google: could not find default credentials. といエラーが出力される場合は gcloud auth application-default login で アプリケーションのデフォルトクレデンシャルを設定してみましょう。

  • Cloud Build でビルドの結果を、GCP コンソールから確認。
    image.png

  • 無事デプロイに成功すると、サンプルアプリの URL が表示れるので、そちらにアクセス
    image.png

  • Guestbook が正常に展開されたことを確認
    image.png

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10