GCP 101: Getting Started through Cloud Run

923237754890d536819892ad42451555?s=47 sakajunquality
December 14, 2019

GCP 101: Getting Started through Cloud Run

923237754890d536819892ad42451555?s=128

sakajunquality

December 14, 2019
Tweet

Transcript

  1. GCP 101: Getting Started through Cloud Run Jun Sakata @sakajunquality

    Google Developers Expert, Cloud 14 December 2019 #DevFest19 #GDGTokyo
  2. This is me - Jun Sakata - Google Developers Expert,

    Cloud - SRE at Ubie, Inc. - Social Media: @sakajunquality - Based in Tokyo - Covered all of Cloud Next this year - My last DevFest this year -
  3. Today’s Goal - Getting started with GCP - Being able

    to deploy app on Cloud Run - Have an overview of Cloud Run - Be production ready
  4. I will not cover... - General serverless computing models -

    Detailed container technology - Docker Best Practices - Microservices principles - Databases - Machine Learning - etc...
  5. Google Cloud Platform

  6. GCP Products - Network - Compute - Database - Data

    Analytics - Machine Learning
  7. VMs

  8. Demo

  9. Serveless

  10. Demo

  11. Serverless Functions

  12. Serverless Functions

  13. Serverless Computing in GCP

  14. Serverless Computing in GCP Cloud Functions App Engine Cloud Run

  15. Container

  16. Docker - Create, Deploy and Run using Containers - Using

    Linux cgroup and namespace - De facto standard format for containers docker image build … docker image push … docker container run …
  17. Kubernetes - Container Platform based on Google’s Borg - Borg

    has supported Google’s service over 12+ years - Orchestrates computing, networking, and storage infrastructure - Microservices Platform - GKE = Google Kubernetes Engine - Fully-managed version of Kubernetes on GCP
  18. Containers Kubernetes

  19. Containers Kubernetes

  20. None
  21. https://twitter.com/steren/status/1115648277356077058

  22. None
  23. https://twitter.com/ahmetb/status/1195056373983145984

  24. Cloud Run - Generally Available - Fully-managed serverless environment -

    Knative API Compatible - Deploy Container - Container with HTTP listening to $PORT - Pay for CPU and memory @100ms + network transfer
  25. Cloud Run - Managed Endpoint - Custom Domains - SSL

    Termination - 1-80 concurrent requests per instance - Default to 80 - Auto scaling from Zero to 1000 instances scale - Default to 1000
  26. Cloud Run - Cloud SQL connection - Serverless VPC connection

    - not yet available as of 13 Dec 2019
  27. Some Limitations for Cloud Run - CPU: 1 vCPU -

    RAM: 128MB ~ 2GB (Default to 256MB) - Timeout: 15min (Default to 5 min)
  28. Pricing - https://cloud.google.com/run/pricing?hl=en

  29. https://github.com/meteatamel/knative-tutorial

  30. Demo

  31. 3 Steps to Deploy! Make App - Any Language -

    Listen to $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3
  32. 3 Steps to Deploy! Make App - Any Language -

    Listen to $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3
  33. Make App - Any Language, any Framework - Listen to

    HTTP on $PORT // main.go package main // ... func main() { r := chi.NewRouter() r.Get("/", func(w http.ResponseWriter, r *http.Request) { m := &Message{ Status: http.StatusOK, Text: os.Getenv("MESSAGE"), } render.JSON(w, r, m) }) port := os.Getenv("PORT") if port == "" { port = "8080" } log.Fatal(http.ListenAndServe(":"+port, r)) } // ...
  34. 3 Steps to Deploy! Make App - Any Language -

    Listen to $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3
  35. Containerize - Make it in to a Docker container //

    Dockerfile FROM golang:1.13 as go FROM gcr.io/distroless/base-debian10 as run FROM go as build WORKDIR /go/src/app COPY go.mod . COPY go.sum . RUN go mod download COPY . . RUN go build -o /go/bin/app FROM run COPY --from=build /go/bin/app /usr/local/bin/app CMD ["app"] $ docker image build … $ docker image push … $ docker container run …
  36. https://www.slideshare.net/Docker/dcsf19-dockerfile-best-practices

  37. https://medium.com/@tonistiigi/advanced-multi-stage-build-patterns-6f741b852fae

  38. 3 Steps to Deploy! Make App - Any Language -

    Listen to $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3
  39. Deploy - Cloud Console or gcloud command $ gcloud run

    deploy my-app --image=gcr.io/...
  40. 3 Steps to Deploy! Make App - Any Language -

    Listen to $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3
  41. What’s next? Make App - Any Language - Listen to

    $PORT Containerize - docker build ... - docker push ... Deploy - gcloud run deploy - run run run 1 2 3 4 ???
  42. What’s next with Cloud Run? - CI/CD - Authentication -

    Firebase Integration - Database - gRPC Protocol - and more ….!
  43. CI/CD

  44. CI/CD - Previously built and deployed manually… - For production

    automated CI/CD is mandatory
  45. Cloud Build - Fully-managed CI - https://cloud.google.com/cloud-build/ - Save Artifact

    to GCR/GCS - Deploy to GCP products - Manual submit or Trigger - Configuration - cloudbuild.yaml or Dockerfile
  46. CI/CD with Cloud Build Cloud Build Build Image Save image

    Container Registry (GCR) Cloud Run Deploy Use image
  47. CI/CD with Cloud Build // cloudbuild.yaml steps: - name: gcr.io/cloud-builders/docker

    args: - image - build - -t - gcr.io/$PROJECT_ID/my-api - . dir: app // continues - name: gcr.io/cloud-builders/docker args: - image - push - gcr.io/$PROJECT_ID/my-api // continues
  48. CI/CD with Cloud Build - name: gcr.io/cloud-builders/gcloud args: - run

    - deploy - demo-app - --image=gcr.io/$PROJECT_ID/demo-app - --platform=managed - --region=asia-northeast1 - --allow-unauthenticated - --set-env-vars - MESSAGE=HELLO!!!! - --project=$PROJECT_ID
  49. Demo

  50. CI/CD with GitHub Actions Official Resource https://github.com/GoogleCloudPlatform/github-actions // ... -

    uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: version: '270.0.0' service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} // ...
  51. CI/CD with Terraform https://twitter.com/steren/status/1202308468645826560

  52. Authentication

  53. Authentication Like microservices, service-to-service authentication might be required Service A

    Service B Implement Authentication…?
  54. Authentication Or Managed-Service integration like Cloud Pub/Sub, Cloud Tasks and

    Cloud Scheduler Cloud Pub/Sub Service Implement Authentication…?
  55. Authentication Cloud Run can use Cloud IAM to authenticate! Service

    A Service B Service A has roles/run.invoker privileges Service B is deployed with --no-allow-unauthenticated option
  56. https://medium.com/google-cloud-jp/gcp-%E3%81%8B%E3%82%89%E3%81%AE-http-%E3%83%AA%E3%82% AF%E3%82%A8%E3%82%B9%E3%83%88%E3%82%92%E3%82%BB%E3%82%AD%E3%83%A5%E3%82% A2%E3%81%AB%E8%AA%8D%E8%A8%BC%E3%81%99%E3%82%8B-dda4933afcd6

  57. Firebase Integration

  58. Firebase Integration Cloud Run can be combined with Firebase Hosting

    Client /foo /bar
  59. Firebase Integration - Cloud Run can be integrated with Firebase

    Hosting with “run” - Cache can be controlled with http headers // firebase.json { "hosting": { "public": "static", "rewrites": [ { "source": "**", "run": { "serviceId": "hello-run", "region": "asia-northeast1" } }, { "source": "/static/**", "destination": "/static/index.html" } ] } } $ firebase deploy
  60. Demo

  61. Database

  62. Database Access - Non-VPC resources - Cloud Firestore - Cloud

    Spanner - etc… - VPC resources - Cloud Memorystore - other VPC resources... - Cloud SQL (RDB)
  63. Database Access - Non-VPC resources - Cloud Firestore - Cloud

    Spanner - etc… - VPC resources - Cloud Memorystore - other VPC resources... - Cloud SQL (RDB) Google Cloud SDK Deploy Run w/ --add-cloudsql-instances option Wait for Serverless VPC Access
  64. gRPC Protocol

  65. https://ahmet.im/blog/grpc-auth-cloud-run/

  66. https://github.com/steren/awesome-cloudrun

  67. Need more flexible environment?

  68. None
  69. Kubernetes - 16:05~ @ B202 - @amsy810

  70. https://twitter.com/kelseyhightower/status/935252923721793536

  71. Choose the right platform?

  72. https://cloud.google.com/blog/products/containers-kuberne tes/when-to-use-google-kubernetes-engine-vs-cloud-run-f or-containers

  73. https://www.youtube.com/watch?v=wzPmgWJ5fpU

  74. Takeaways

  75. Takeaways 1/2 - Cloud Run is a container serverless platform.

    - You can run any container listening http on $PORT - Cloud Run allows you to deploy containerized applications with a single command or a few clicks. - Cloud Run can use most of the GCP resources - API, Database, Storage … - More features are coming!
  76. Takeaways 1/2 - Kubernetes is not only option for running

    containers. - (for the record I love Kubernetes) - Choose the right platform depending on your app and team!
  77. Kubernetes - 16:05~ @ B202 - @amsy810

  78. Try Following - @ahmetb - @steren - @martinomander - @glaforge

    - @meteatamel - @alexismp
  79. Thank you