LoginSignup
8
6

More than 3 years have passed since last update.

VSCode拡張機能の「Cloud Code」

Last updated at Posted at 2019-11-29

概要

Googleが提供するVSCodeでkubernetes(GKE)の作成、デプロイなどを簡単に行えるようになるツールです。
日本語ではまだβになっていますが、英語版では正式リリースになっています。
Googleが開発していますが、AWSやAzureのマネージドKubernetesにも対応しているようです。

環境

  • MacOSX
    • Catalina 10.15.1
  • Visual Stadio Code
    • Version: 1.40.2
  • gcloud
    • Google Cloud SDK 271.0.0
    • 認証済み
  • Docker
    • version 19.03.5
  • Skaffold

How to Use

インストールから実際の使い方まで

インストール

Cloud Codeで検索すると出てきます。
(画像はすでにインストール済み)
スクリーンショット 2019-11-29 10.26.53.png

実際の動作


GKEクラスターの作成

コマンドパレットにCloud Codeと入力すると候補が出ます。
Cloud Code:Create GKE clusterを選択します。
スクリーンショット 2019-11-29 10.31.32.png

クラスターの設定画面が表示されるので順次設定していきます。

  • Step1 プロジェクトIDの設定
    クラスターを作成するプロジェクトIDを入力します。

スクリーンショット 2019-11-29 10.36.09.png

  • Step2 リージョン/ゾーンの選択
    リージョンでasia-northeast1を選択します。

スクリーンショット 2019-11-29 10.40.18.png

  • Step3 詳細設定
    クラスターの名前やノード数、ノードインスタンスの種類を設定します。

スクリーンショット 2019-11-29 10.43.32.png

入力したらCreate Clusterボタンを押下してしばらく待ちます。

クラスター作成中・・・
スクリーンショット 2019-11-29 10.50.00.png

クラスター作成完了
スクリーンショット 2019-11-29 10.58.56.png

作成したGKEクラスターの確認

インストールするとアイコンが追加されます。
これでKubernetesのクラスターを確認できます。
スクリーンショット 2019-11-29 12.04.21.png
クラスター作っただけなんで中身は何もありません。

新しいクラスターの作成

Cloud Code: New Applicationを選択すると新しいクラスターが作成できます。
スクリーンショット 2019-11-29 12.13.30.png

なんでもいいんですが、とりあえずGoにしました。
スクリーンショット 2019-11-29 12.16.14.png

ルートディレクトリを決めます。
スクリーンショット 2019-11-29 12.19.13.png

デフォルトでは${HOME}/cloudcode-projects/go-hellow-world-1になっていました。
VSCodeが今開いてるフォルダにしろ
ファイルが作成されます。
スクリーンショット 2019-11-29 12.23.22.png

作成したクラスターの実行

Cloud Code: deployを選択します。
スクリーンショット 2019-11-29 12.45.10.png

ローカルのDockerを利用するためDefaultを選択します。
スクリーンショット 2019-11-29 12.59.36.png

コンテナのビルドやリソースのデプロイが行われます

ビルドデプロイログ
Running: skaffold run --enable-rpc -v info --rpc-http-port 59310 --filename skaffold.yaml
Running: skaffold dev -v info --rpc-http-port 59346 --filename skaffold.yaml
Running: skaffold run --enable-rpc -v info --rpc-http-port 59353 --filename skaffold.yaml
Running: skaffold run --enable-rpc -v info --rpc-http-port 59363 --filename skaffold.yaml
starting gRPC server on port 50051
starting gRPC HTTP server on port 59363
Using kubectl context: docker-desktop
Generating tags...
 - go-hello-world -> go-hello-world:latest
Checking cache...
Tags generated in 96.073µs
 - go-hello-world: Not found. Building
Found [docker-desktop] context, using local docker daemon.
Building [go-hello-world]...
Cache check complete in 2.724232184s
Sending build context to Docker daemon  57.34kB

Step 1/8 : FROM golang:1.13
1.13: Pulling from library/golang
16ea0e8c8879: Pulling fs layer
50024b0106d5: Pulling fs layer
ff95660c6937: Pulling fs layer
9c7d0e5c0bc2: Pulling fs layer
2a19d2e6789c: Pulling fs layer
bd9cab5aeb31: Pulling fs layer
0ed236c95063: Pulling fs layer
2a19d2e6789c: Waiting
bd9cab5aeb31: Waiting
0ed236c95063: Waiting
9c7d0e5c0bc2: Waiting
ff95660c6937: Verifying Checksum
ff95660c6937: Download complete
50024b0106d5: Verifying Checksum
50024b0106d5: Download complete
9c7d0e5c0bc2: Verifying Checksum
9c7d0e5c0bc2: Download complete
16ea0e8c8879: Verifying Checksum
16ea0e8c8879: Download complete
0ed236c95063: Verifying Checksum
0ed236c95063: Download complete
16ea0e8c8879: Pull complete
50024b0106d5: Pull complete
ff95660c6937: Pull complete
bd9cab5aeb31: Verifying Checksum
bd9cab5aeb31: Download complete
2a19d2e6789c: Verifying Checksum
2a19d2e6789c: Download complete
9c7d0e5c0bc2: Pull complete
2a19d2e6789c: Pull complete
bd9cab5aeb31: Pull complete
0ed236c95063: Pull complete
Digest: sha256:f9de064473fb30c66bc0d2ddf2cf9a4a9bd38cbd2c5e59ce3bdf8af7b8747a57
Status: Downloaded newer image for golang:1.13
 ---> a2e245db8bd3
Step 2/8 : RUN go get -u -v github.com/go-delve/delve/cmd/dlv
 ---> Running in e6193a3a906d
[91mgithub.com/go-delve/delve (download)
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/loclist
[0m[91mgithub.com/go-delve/delve/vendor/go.starlark.net/internal/spell
[0m[91mgithub.com/go-delve/delve/vendor/github.com/mattn/go-isatty
[0m[91mgithub.com/go-delve/delve/vendor/gopkg.in/yaml.v2
[0m[91mgithub.com/go-delve/delve/pkg/goversion
[0m[91mgithub.com/go-delve/delve/vendor/golang.org/x/sys/unix
[0m[91mgithub.com/go-delve/delve/vendor/github.com/cosiner/argv
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/util
[0m[91mgithub.com/go-delve/delve/vendor/golang.org/x/arch/arm64/arm64asm
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/op
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/godwarf
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/frame
[0m[91mgithub.com/go-delve/delve/pkg/config
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/line
[0m[91mgithub.com/go-delve/delve/pkg/dwarf/reader
[0m[91mgithub.com/go-delve/delve/vendor/golang.org/x/arch/x86/x86asm
[0m[91mgithub.com/go-delve/delve/vendor/golang.org/x/crypto/ssh/terminal
[0m[91mgithub.com/go-delve/delve/vendor/github.com/peterh/liner
[0m[91mgithub.com/go-delve/delve/vendor/go.starlark.net/syntax
[0m[91mgithub.com/go-delve/delve/vendor/github.com/sirupsen/logrus
[0m[91mgithub.com/go-delve/delve/pkg/version
[0m[91mgithub.com/go-delve/delve/vendor/github.com/spf13/pflag
[0m[91mgithub.com/go-delve/delve/pkg/logflags
[0m[91mgithub.com/go-delve/delve/vendor/go.starlark.net/resolve
[0m[91mgithub.com/go-delve/delve/pkg/proc
[0m[91mgithub.com/go-delve/delve/vendor/go.starlark.net/internal/compile
[0m[91mgithub.com/go-delve/delve/vendor/github.com/spf13/cobra
[0m[91mgithub.com/go-delve/delve/vendor/go.starlark.net/starlark
[0m[91mgithub.com/go-delve/delve/pkg/proc/winutil
[0m[91mgithub.com/go-delve/delve/pkg/proc/linutil
[0m[91mgithub.com/go-delve/delve/service/api
[0m[91mgithub.com/go-delve/delve/pkg/proc/core/minidump
[0m[91mgithub.com/go-delve/delve/pkg/proc/gdbserial
[0m[91mgithub.com/go-delve/delve/service
[0m[91mgithub.com/go-delve/delve/pkg/proc/core
[0m[91mgithub.com/go-delve/delve/pkg/proc/native
[0m[91mgithub.com/go-delve/delve/service/debugger
[0m[91mgithub.com/go-delve/delve/service/rpc1
[0m[91mgithub.com/go-delve/delve/service/rpc2
[0m[91mgithub.com/go-delve/delve/service/rpccommon
[0m[91mgithub.com/go-delve/delve/pkg/terminal/starbind
[0m[91mgithub.com/go-delve/delve/pkg/terminal
[0m[91mgithub.com/go-delve/delve/cmd/dlv/cmds
[0m[91mgithub.com/go-delve/delve/cmd/dlv
[0m ---> 9c239a04a8c2
Step 3/8 : WORKDIR /src/hello-world
 ---> Running in 4d80d86a1faa
 ---> d787f60f40eb
Step 4/8 : COPY go.mod go.sum ./
 ---> 8b3ab925a778
Step 5/8 : RUN go mod download
 ---> Running in 28efd6611102
 ---> 1c589d3b4d0a
Step 6/8 : COPY . ./
 ---> 5c6d6d2c96ef
Step 7/8 : RUN go build -o /app -v ./cmd/hello-world
 ---> Running in 5ccba50bc0d6
[91mhello-world/cmd/hello-world
[0m ---> df16dd9586b8
Step 8/8 : ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]
 ---> Running in c0e015fa2785
 ---> 836c47e159b2
Successfully built 836c47e159b2
Successfully tagged go-hello-world:latest
Build complete in 54.230696113s
Tags used in deployment:
 - go-hello-world -> go-hello-world:836c47e159b26b333365a1c23efe5ffbf1a1ac4474ef19f94dae8c613a6278ee
   local images can't be referenced by digest. They are tagged and referenced by a unique ID instead
Starting deploy...
 - deployment.apps/go-hello-world created
 - service/go-hello-world-external created
Deploy complete in 618.346232ms
You can also run [skaffold run --tail] to get the logs
There is a new version (1.0.1) of Skaffold available. Download it at https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64

Waiting for Deployment 'go-hello-world' to rollout...
Waiting for IP address of Service 'go-hello-world-external'.

Publicly exposed service endpoints in the application:
go-hello-world-external: http://localhost:80


No ingress endpoints found in the application.
Application deployed successfully.

最後にアクセスするためのアドレスが出ます。

go-hello-world-external: http://localhost:80

このURLにアクセスするとデプロイされたアプリにアクセスできます。
スクリーンショット 2019-11-29 13.08.30.png

デプロイ後の構成はKUBERNETES EXPLORERで見ることができます。
スクリーンショット 2019-11-29 13.12.23.png

感想

kubernetesは単純に動作させたりするだけでもそこそこ長い(当社比)yaml書かなければならなかったり、動作後のログや構成なんか見るのも大変なのですが、こうして各モジュールの状態とか簡単に見られるようになります。
k9sというツールもあるみたいなので、そちらの方もチェックしてみようかと思います。

なんだこのアイコンは
k9s

8
6
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
8
6