Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Serverless Workshop London 2019 - Modern use-cases in the serverless architecture

Mark Chmarny
November 18, 2019

Serverless Workshop London 2019 - Modern use-cases in the serverless architecture

Cloud Run is a managed compute platform that automatically scales stateless containers. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications. Run your containers in fully managed Cloud Run or on any other Knative comptable platform, ensuring that your applications are built on an open standard.

This workshop provided an overview of Cloud Run and demonstrated many of the common developer and operational patterns used to run real-world solutions. In this 3 hour long workshop participants:
- Learned what Serverless is and what are its benefits
- Reviewed key features of Cloud Run using live demos
- Built and deployed your own serverless workloads during hand-on labs

Mark Chmarny

November 18, 2019
Tweet

More Decks by Mark Chmarny

Other Decks in Technology

Transcript

  1. Serverless Workshop Modern use-cases in the serverless architecture Developer Advocate,

    Google @mchmarny
  2. Context

  3. Serverless more than Function

  4. Service-based Event-driven Open Serverless Usage Model Developer Model

  5. Serverless more than Compute

  6. Compute Data Analytics ML & AI Database & Storage Smart

    assistants & chat DevOps Messaging Serverless Patterns • No infrastructure to manage • Composable architecture • Integrated logging/monitoring • Managed security • Pay only for usage
  7. Serverless and Container

  8. .js .rb .go .py .sh … 0 1 0 1

    0 0 1 1 1 Containers • Any Language, Library, Binary • Granular version control • Ecosystem of base images Common unit of workload description (Dockerfile) and delivery (Container Image)
  9. Serverless with Portability

  10. Knative Enables Portability • Codifies serverless containers • Builds on

    Kubernetes ubiquity • Has a broad community support knative.dev
  11. Cloud Run Introduction

  12. Cloud Run Stateless containers on Google’s fully-managed compute platform cloud.run

  13. Cloud Run Functionality • Activates/scales workload based on HTTP/gRPC request

    (up/down to 0) • Manages code/config as immutable revisions (rollback, split traffic) • Provides Services access, resources usage, and concurrency control • Integrates metrics and logging, Custom domains, TLS support,.. Integration • Connects with other GCP services like Cloud SQL, Cloud Build, Cloud PubSub, Cloud Tasks • Extend with partner integrations like GitLab, Datadog
  14. Cloud Run “flavors” Cloud Run (fully managed) • Fully serverless

    • No cluster to manage • Pay for what you use Cloud Run on Anthos • Runs in your GKE cluster • Serverless developer experience • Custom node types, accelerators, VPC
  15. Cloud Run Usage

  16. Deployment gcloud run deploy service-name \ --image gcr.io/project/image-name Options for:

    • Concurrency • RAM/CPU • Maximum Instances • Request Authentication • Service Identity • Environment Variables • Labels • Scaling Limits • ... Demo: github.com/mchmarny/maxprime
  17. Service URL Services-generated URL, responds only to HTTPS and non-streaming

    gRPC https://maxprime-2gtouos2pq-uc.a.run.app Supports custom domains and auto TLS (using Let’s Encrypt): https://run.demome.tech
  18. Cloud Run Metrics & Logs Logging Automatically captures two types

    of logs in Stackdriver: • Request logs • Container logs (/var/log, stdout, stderr) Metrics • Performance and uptime metrics Metrics and logs are available directly in Cloud Run, or in Stackdriver UI with additional charting, filtering, alerting options
  19. Cloud Run Autoscaling Each revision scales automatically to the number

    of container instances needed to handle all incoming requests The actual number of instances is impacted by concurrency and maximum number of instances settings
  20. Cloud Run Concurrency concurrency: 1 concurrency: 3-n Fewer Cold Starts

    More requests per container instance means fewer instances for the same QPS Faster Scale Up Fewer new container instances means faster traffic spikes response (cold starts) Better Utilization Instances spend less time with idle resources, which is a more efficient use of resources vs Container
  21. Cloud Run Billable Time Instance Billable Time Request 1 Start

    Request 1 End Request 2 Start Request 2 End Instance Time Billable Non-billable
  22. Per-Request Billing vCPU, Memory, Requests 100ms First 180K vCPU-sec, 360K

    GB-sec, and 2M requests are free cloud.google.com/run/pricing
  23. Container Image

  24. Cloud Run Workload Cloud Run “runs” any code written in

    any language using any library, but… It must be Linux x86-64 compiled and packaged into a container image Other things to consider: • Listens on port defined in environment variable • Is stateless (no persistent file system) • Starts fast (shorter activation better) • Completes with a response (no long running jobs, activity after request has completed significantly throttled) cloud.google.com/run/quotas
  25. Local Docker Build with Dockerfile docker build -t user/app:version; docker

    push ... Remote Build Service with Dockerfile (e.g. Cloud Build) git commit/push, repo trigger on release tag demo: github.com/mchmarny/maxprime Docker daemon-less Build without Dockerfile (e.g. JIB) JIB plugin for Maven or Gradle demo: github.com/mchmarny/knative-demos Container Image Build Options
  26. Cloud Run Integrations

  27. Cloud PubSub Integration Cloud Run Cloud PubSub Stream Stream Stream

  28. Cloud Storage Object Processing Cloud Storage Cloud PubSub Topic Processing

    Stream Bucket Upload Storage Cloud Run Service PDF Creation put push Lab 2 Bucket Result Storage Subscription Service Push pub put
  29. Cloud Build Status Notifications Cloud Build Github Repo Release Cloud

    PubSub Topic Build Status Job Image, Push, Deploy Cloud Run Service New Revision trigger push Service Slack Notifications Slack Channel #build-status push Demo: github.com/mchmarny/buildstatus
  30. Cloud Scheduler Integration Command Line Interface (CLI) User Interface (UI)

    Scheduler API Cloud Run Cloud Scheduler
  31. Cloud Scheduler Service Invoker Schedule Cloud Scheduler Service Invocation Demo:

    github.com/mchmarny/tweet-provider Cloud Run Service Invoker Schedule Cloud PubSub Search Results Topic Twitter Searcher Service Cloud Firestore Search State Collection Stackdriver Service Logs Logging Event Throughput Metrics Search Consumers Subscriptions Search Invoker Schedule
  32. Stackdriver Integration Cloud Run Stackdriver Metric Metric Metric

  33. BigQuery Stackdriver Batch BigQuery Insert Cloud PubSub Topic Event Stream

    Cloud Run Service Batch Insert webhook Metric Alert Age/Number pub monitor Table Processing Stream Subscription Processing Stream sub insert Demo: github.com/mchmarny/pubsub-to-bigquery-pump
  34. Usage Patterns

  35. Cloud Run Service Updates

  36. Knative Object Model Revision 1 Revision 2 Revision 3 Configuration

    Route Service Route - named endpoint and a mechanism for routing traffic Revisions - immutable snapshots of code + config Configuration - stream of environments for Revisions Service - top-level wrapper for managing Route/Configurations sets
  37. Cloud Run Service Updates Traffic Live Service Traffic # Initial

    state # Spin up “Blue” # version with # new code/features Live Service Traffic # Shift traffic over # from “Green” version # to new “Blue” version New Revision Live Service Old Revision (or Rollback)
  38. gcloud alpha run services update-traffic ab \ --to-revision ab-v1=90,ab-v2=10 Traffic

    Management Demo: github.com/mchmarny/ab-test-demo Split traffic across multiple revisions
  39. Traffic Management

  40. Cloud Run Access Management

  41. Cloud Run Service Access Public Service • Website • API

    endpoint Internal Service • Backing Microservices • Eventing Targets • Mobile backend • Webhook
  42. Access Management GCP Cloud Run Logo Service Vision API User

    HTTPS HTTPS curl -H "Content-Type: application/json" \ -d '{"id":"test","url":"https://storage.googleapis.com/kdemo-logos/google.png"}' \ https://logo.demo.cloudylabs.dev/
  43. Access Management GCP Cloud Run Frontend UI Logo Service User

    Service Vision API Firestore API User HTTPS Demo: logoui.demo.cloudylabs.dev OAuth HTTPS HTTPS
  44. Access Management GCP Cloud Run Frontend UI Logo Service User

    Service Vision API Firestore API User HTTPS OAuth HTTPS HTTPS Demo: logoui.demo.cloudylabs.dev
  45. Access Management GCP Cloud Run Frontend UI Internal Logo Service

    Internal User Service Vision API Firestore API User HTTPS OAuth HTTPS HTTPS Demo: logoui.demo.cloudylabs.dev
  46. In Closing

  47. Docs, Quick Starts cloud.run StackOverflow tag google-cloud-run Samples knative.dev Anything

    else @mchmarny
  48. Cloud Run Labs

  49. Labs Setup Make sure you are using modern browser and

    are connected to WiFi 1. Setup QwikLabs Account google.qwiklabs.com 2. Get Tokens
  50. Lab 1: Deploying stateless container Make sure you have verified

    QwikLabs account email 1. Navigate to bit.ly/cr-lab1 2. Setup GCP account and new project 3. Deploy container to Cloud Run
  51. Lab 2: Build a Serverless App Get a new token

    if your time is almost expired 1. Navigate to bit.ly/cr-lab2 2. Build service to create PDFs from Cloud Storage files
  52. Docs, Quick Starts cloud.run StackOverflow tag google-cloud-run Samples knative.dev Anything

    else @mchmarny