🐫

Cloud Runの情報をさっくりまとめ

2021/08/17に公開

Cloud Run

特徴(下の参考)から抜き出したやつ。

  • Knativeを元に構築されている。
  • 他のサーバーレスプラットフォームがイベントドリブンの関数をデプロイメントの主な単位としているのに対し、Cloud Runではコードをステートレスなコンテナにパッケージ化して、HTTPリクエスト経由で呼び出すことができる
  • インフラストラクチャの管理が不要、従量課金、容易に自動拡張できる
  • Cloud RunではコンテナをGoogle Kubernetes Engine (GKE)にデプロイすることもできる

公式のページで、いろいろ書いてある。

https://cloud.google.com/blog/topics/developers-practitioners/cloud-run-story-serverless-containers

  • No vendor lock-in - Because Cloud Run takes standard OCI containers and implements the standard Knative Serving API, you can easily port over your applications to on-premises or any other cloud environment.
  • Fast autoscaling - Microservices deployed in Cloud Run scale automatically based on the number of incoming requests, without you having to configure or manage a full-fledged Kubernetes cluster. Cloud Run scales to zero— that is, uses no resources—if there are no requests.
  • Split traffic - Cloud Run enables you to split traffic between multiple revisions, so you can perform gradual rollouts such as canary deployments or blue/green deployments.
  • Custom domains - You can set up custom domain mapping in Cloud Run and it will provision a TLS certificate for your domain.
  • Automatic redundancy - Cloud Run offers automatic redundancy so you don’t have to worry about creating multiple instances for high availability

カナリアリリースやブルーグリーンデプロイメントができるというのは知らなかった。

参考

Cloud Functionsとの比較

Cloud Run and Cloud Function: What do I use? And Why?では「stateless HTTP containerに対してはCloud Runが使いやすい」と述べていて、2つのメリットを挙げている。

  • Portability
  • Testability

ちょっとしたイベントドリブンなコードをサーバレスでやりたい、ただテストコードを書くほどでもない規模で、というのであれば、Cloud Functionsは良さそう。テストケースを十分用意したり複雑な入力を求めるHTTPエンドポイントなどはCloud Runの方が良さそう。

https://cloud.google.com/blog/topics/developers-practitioners/cloud-run-story-serverless-containers

にも「How is Cloud Run different from Cloud Functions?」と書いてある。3つある。

1つめ 「言語の選択の制約が少なめ」

Cloud Functions lets you deploy snippets of code (functions) written in a limited set of programming languages, while Cloud Run lets you deploy container images using the programming language of your choice.

2つめ 「好きなライブラリやツールを組み込める」

Cloud Run also supports the use of any tool or system library from your application; Cloud Functions does not let you use custom executables.

3つめ 「タイムアウト時間が長い」

Cloud Run offers a longer request timeout duration of up to 60 minutes, while with Cloud Functions the requests timeout can be set as high as 9 mins.

4つめ 「並列稼働」

Cloud Functions only sends one request at a time to each function instance, while by default Cloud Run is configured to send multiple concurrent requests on each container instance. This is helpful to improve latency and reduce costs if you're expecting large volumes.

このページにもまとまっていた。

https://firebase.google.com/docs/hosting/serverless-overview

開発者が、あるプロジェクトをCloud Runで動かすまで

  • Dockerで動くプロジェクトを用意。
  • Container RegistryにDocker imageをpushする。
  • Container RegistryのDocker imageからCloud Runのインスタンスを作成する。

参考

参考

Discussion