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

Going Serverless with Artifactory and Containers on Cloud Run — SwampUp 2021

Going Serverless with Artifactory and Containers on Cloud Run — SwampUp 2021

On Google Cloud, modern workloads are running containers, in a serverless fashion. With Cloud Run, you can easily deploy your workloads, and have them scale up and down transparently to accommodate traffic spikes as well as low demand. In this session, we’ll introduce you to the serverless container world of Cloud Run, how to build them with Cloud Build, and we’ll see how we can take advantage of JFrog Artifactory for hosting our container artifacts. In a series of live demos, we will demonstrate different Cloud Run use cases. Legacy Monolith, Machine Learning API, Vault, Microservices or Event Based Architecture — Google Cloud Run and JFrog will get you covered!

Guillaume Laforge

June 02, 2021
Tweet

More Decks by Guillaume Laforge

Other Decks in Technology

Transcript

  1. Going Serverless with Artifactory and Containers on Cloud Run Guillaume

    Laforge Developer Advocate @ Google Ayrat Khayretdinov CNCF Ambassador, Hybrid Cloud Specialist @ Google @glaforge @archyufa
  2. Proprietary + Confidential The serverless models and characteristics Operational Model

    Programming Model No Infra Management Managed Security Pay only for usage Service-based Event-driven Stateless
  3. Proprietary + Confidential FaaS App platform Container Virtual machine The

    serverless spectrum Dedicated server Physical hardware Virtual hardware Operation system Application runtime Application Function Virtual hardware Operation system Application runtime Application Function Operation system Application runtime Application Function Application Function Function Serverless Zone
  4. Proprietary + Confidential Develop and deploy highly scalable containerized applications

    on a fully managed serverless platform • Write code your way using your favorite languages (Go, Python, Java, Ruby, Node.js, and more) • Abstract away all infrastructure management for a simple developer experience • Built upon an open standard Knative, enabling the portability of your applications Cloud Run
  5. Proprietary + Confidential Serverless containers with Knative and Cloud Run

    Cloud Run Fully managed, deploy your workloads and don’t see the cluster. Cloud Run on Anthos Deploy into Anthos, run serverless side-by-side with your existing workloads. Knative everywhere Use the same APIs and tooling anywhere you run Kubernetes with Knative.
  6. Proprietary + Confidential Containers Any language Rich ecosystem Any library

    of base images Any binary .js .rb .go .py .sh … 0 1 0 1 0 0 1 1 1 Containers Flexibility Serverless Velocity
  7. Proprietary + Confidential Container contract... and resources • Listen on

    0.0.0.0 on port $PORT (default 8080) • HTTP server must start < 4 min (timeout → 504) • Request time < 15 min (default → 5 min, up to 60 min) • Stateless (in-memory file system) • Computation only within request (No background activity) • 1 vCPU per container instance (configurable to 4 vCPU) • 256 MiB of memory up to a max of 8 GiB (configurable, soon 16 GiB) • 80 concurrent requests per container (configurable 1-80, soon 250) • 100 max containers by default (configurable 1-1000, support overridable) • Sandboxed by gVisor
  8. Proprietary + Confidential Billable time Instance Billable Time Request 1

    Start Request 1 End Request 2 Start Request 2 End Instance Time Billable Non-billable
  9. Gradual rollouts & Rollbacks Specify % traffic between revisions Blue

    / Green deployments Get URLs for specific revisions # Gradual rollout $ gcloud beta run deploy myservice \ --image gcr.io/project/image:f5bd774 \ --no-traffic \ --tag green $ gcloud beta run services update-traffic myservice \ --to-tags green=1 $ gcloud beta run services update-traffic myservice \ --to-tags green=10 $ gcloud beta run services update-traffic myservice \ --to-tags green=50 $ gcloud beta run services update-traffic myservice \ --to-tags green=100 # Rollback $ gcloud run services update-traffic myservice --to-revisions my-service-0002-joy=100 $ curl https://green---myservice-12345-us.a.run.app
  10. GCP Project VPC Access Connect to Cloud Memorystore Redis and

    Memcached Connect to private IPs Shared VPC Cloud Run Serverless VPC Connector Cloud Memorystore VM Compute Engine Virtual Private Cloud Private IP Private IP
  11. Cloud Workflows Orchestrate serverless tasks Fully managed. Use cases: •

    Process events • Chaining API calls • Automate infra management • Implement retry policies GCP Project Start Every day at 6pm Get list of all dev VMs End For each VM: Is it running ? Extract status Stop VM Email owner
  12. Min instances Keep a number of instances warm Use to

    avoid cold starts Lower instance price when not in use Container Instances min = 2 0
  13. Graceful instance termination Receive a SIGTERM signal before container instance

    is terminated. If handled, CPU is allocated for 10s max $ cat index.js const process = require('process'); process.on('SIGTERM', () => { console.log('Container is shutting down...'); // TODO: Close database connections // TODO: Send any buffered telemetry data }); ...
  14. gRPC support $ cat main.go … func main() { port

    := os.Getenv("PORT") listener, err := net.Listen("tcp", ":"+port) grpcServer := grpc.NewServer() pb.RegisterPingServiceServer(grpcServer, &pingService{}) if err = grpcServer.Serve(listener); err != nil { log.Fatal(err) } }
  15. Server-side streaming Server-Sent Events, WebSockets. Stream HTTP or gRPC responses

    Responses no more buffered and limited to 32MB $ cat main.go … http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "video/mp4") w.Header().Set("Transfer-Encoding", "chunked") f, _ := os.Open("videos/demo.mp4") io.Copy(w, f) }) port := os.Getenv("PORT") log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) (coming soon)
  16. Proprietary + Confidential Cloud Run Use cases More at https://cloud.run

    Serverless Use Cases Cloud Run Build a web or mobile app HTTP web app Bidirectional streaming WebSockets & gRPC Developing APIs Web & mobile backends Internal APIs and services Data Processing Automation Event driven reactive automation Workflow & Orchestration Event driven reactive automation Connecting Cloud Services Stateful Workloads ? Healthcare Gaming Retail Banking
  17. Cloud Run with Jfrog Demo Stack JFrog Cloud Platform on

    GCP - Jfrog Pipelines - Jfrog Docker Artifactory - Jfrog Xray Pull request Trigger Docker Repository CI CD Update Image tag Cloud Run Fully Managed Cloud Run for Anthos Thanks @jenn_viau for helping to build this amazing demo! Code Quality Build Image Scan Image
  18. Amazing Cloud Run Links • Slides - https://speakerdeck.com/cncfcanada • Awesome

    Cloud Run - github.com/steren/awesome-cloudrun • Cloud Run FAQ - github.com/ahmetb/cloud-run-faq • Vault on Cloud Run - gh/kelseyhightower/serverless-vault-with-cloud-run Guillaume Laforge Developer Advocate @ Google Ayrat Khayretdinov CNCF Ambassador, Hybrid Cloud Specialist @ Google @glaforge @archyufa
  19. THANK YOU! Guillaume Laforge Developer Advocate @ Google Ayrat Khayretdinov

    CNCF Ambassador, GDG, GDE Hybrid Cloud Specialist @ Google @glaforge @archyufa
  20. 33 Proprietary + Confidential Application Development Performance Monitoring Serverless Physical

    Servers Network Hardware Physical Security Internet Connectivity Scaling VM Provisioning Ops & Security Management The Responsibility Pyramid Managed by customer Fully Managed by Google
  21. 34 Risk Simplicity Velocity Elasticity Key values of developing, deploying

    and scaling apps in a fully managed environment
  22. 35 Serverless Compute Deploy and scale applications fast and securely

    in a fully managed environment No Infra Management Speed to Market Auto-scaling
  23. “We can’t be locked in.” “How can we use existing

    binaries?” “Why do I have to choose between containers and serverless?” “Can you support language ____ ?” But… customers ask us:
  24. Containers • Any Language • Any Library • Any Binary

    • Ecosystem of base images .js .rb .go .py .sh … 0 1 0 1 0 0 1 1 1
  25. Proprietary + Confidential Cloud Run Deploy in seconds Automatic HTTPS,

    Custom domains Any language, any library Portability No cluster management Run containers on a fully managed environment
  26. Proprietary + Confidential Build a web app Web app Request-based

    services Developing APIs Web & mobile backends Internal APIs and services Data Processing Automation Workflow & Orchestration Event driven reactive automation Connecting Cloud Services Use cases More at https://cloud.run
  27. Get Started Setup Compute CICD Run Other Create Project Setup

    Compute Core Infra Load Balancing Service Mesh Specify Volumes NAT Shared VPC Workload YAML Auto-Scale YAML Cloud Build YAML Deploy Time Test Image Rep. Source Version Control Run 8x faster time to market with Cloud Run! Shared VPC Create Project Deploy Time & Test Source Version Control Image Rep Cloud Build YAML Run
  28. Proprietary + Confidential Engineers 3 Days 2 Containerized app 1

    5.5M Requests per day 700ms Latency €500 a month 40% cost reduction and 80% less effort
  29. Delight developers • Deploy from YAML / Export to YAML

    • Easy Continuous Deployment set up from Git • Develop and run locally • Graceful instance termination • Trigger from 60+ GCP sources (Eventarc) • Cloud Workflows Expand addressable workloads • Min instances • Up to 16GB RAM • Up to 4 CPU • bidirectional gRPC streaming Preview • websockets Preview • HTTP/2 Preview • Long running instances (1hr) What's new? Enterprise Class • VPC connectors: Shared VPC support • Ingress = internal • Egress controls • VPC-SC • Secret Manager integration • Customer Managed Encryption Keys • Binary Authorization • API Gateway support • Identity Aware Proxy support • Cloud Armor support • Committed Use Discounts
  30. Keep delighting developers Enterprise-class Expand addressable workloads • Access and

    Transparency • Liveness and Readiness checks • Always on CPU • Autoscaling improvements • Deterministic URLs, Service Discovery and Service Mesh ✓ Current Current 🠻 🠻 🠻 🠻 • Local development experience (with Cloud Code) • Trigger with events (with Eventarc) • Recommendations and insights (with Recommendation Hub) • Better observability: new metrics, platform errors, tracing (with Cloud Ops) • Infrastructure as code via Config Connector 1. Expand the Cloud Run Service: • Instances: filesystem access, more CPU, more RAM… • Spec: multiple container 2. New resource types: Jobs, non-HTTP services...
  31. Billable time Instance Billable Time Request 1 Start Request 1

    End Request 2 Start Request 2 End Instance Time Billable Non-billable
  32. Gradual rollouts & Rollbacks Specify % traffic between revisions Blue

    / Green deployments Get URLs for specific revisions # Gradual rollout $ gcloud beta run deploy myservice \ --image gcr.io/project/image:f5bd774 \ --no-traffic \ --tag green $ gcloud beta run services update-traffic myservice \ --to-tags green=1 $ gcloud beta run services update-traffic myservice \ --to-tags green=10 $ gcloud beta run services update-traffic myservice \ --to-tags green=50 $ gcloud beta run services update-traffic myservice \ --to-tags green=100 # Rollback $ gcloud run services update-traffic myservice --to-revisions my-service-0002-joy=100 $ curl https://green---myservice-12345-us.a.run.app
  33. GCP Project VPC Access Connect to Cloud Memorystore Redis and

    Memcached Connect to private IPs Shared VPC Cloud Run Serverless VPC Connector Cloud Memorystore VM Compute Engine Virtual Private Cloud Private IP Private IP
  34. Cloud Workflows Orchestrate serverless tasks. Fully managed. Use cases: •

    Process events • Chaining API calls • Automate infra management • Implement retry policies GCP Project Start Every day at 6pm Get list of all dev VMs End For each VM: Is it running ? Extract status Stop VM Email owner
  35. Min instances Keep a number of instances warm. Use to

    avoid cold starts. Lower instance price when not in use. Container Instances min = 2 0
  36. Graceful instance termination Receive a SIGTERM signal before container instance

    is terminated. If handled, CPU is allocated for 10s max $ cat index.js const process = require('process'); process.on('SIGTERM', () => { console.log('Container is shutting down...'); // TODO: Close database connections // TODO: Send any buffered telemetry data }); ...
  37. gRPC support $ cat main.go … func main() { port

    := os.Getenv("PORT") listener, err := net.Listen("tcp", ":"+port) grpcServer := grpc.NewServer() pb.RegisterPingServiceServer(grpcServer, &pingService{}) if err = grpcServer.Serve(listener); err != nil { log.Fatal(err) } }
  38. Server-side streaming Stream HTTP or gRPC responses. Responses no more

    buffered Responses no more limited to 32MB $ cat main.go … http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "video/mp4") w.Header().Set("Transfer-Encoding", "chunked") f, _ := os.Open("videos/demo.mp4") io.Copy(w, f) }) port := os.Getenv("PORT") log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) (coming soon)
  39. Multi-region load balancing via External HTTP(S) Load Balancing Expose a

    global endpoint that routes requests to the closest service. Be resilient to regional outages GCP Project Cloud Load Balancing Cloud Run europe-west1 Cloud Run us-central1 Cloud Run asia-northeast1 San Francisco Paris https://example.com https://example.com
  40. GCP Project Cloud CDN via External HTTP(S) Load Balancing Reduce

    the load on your service and improve its performance by returning Cache-Control headers Cloud Run Cache-Control: public, max-age=30, s-maxage=300 1 2 Cloud CDN Cloud Load Balancing
  41. GCP Project Identity Aware Proxy via External HTTP(S) Load Balancing

    Create internal web apps: • automatic login screen • grant access to users in your org (coming soon) Cloud Run Identity Aware Proxy Cloud Load Balancing ✓ x
  42. Cloud Armor via External HTTP(S) Load Balancing DDoS defense Filter

    traffic by: • IP address • geography Firewall rules Cloud Run Cloud Armor ✓ x Cloud Load Balancing ip-ranges: "198.51.100.0/24" action: "allow" 198.51.100.1 192.0.2.0 GCP Project
  43. Leverage "Invoker" IAM role and service identity. Private service to

    service Frontend Backend IAM: role: "roles/run.invoker" member: "serviceAccount:frontend@..." header:"Authorization: Bearer ID_TOKEN"
  44. Push Events with Pub/Sub Pub/Sub push to Cloud Run URL

    with authentication token. Leverage "Invoker" IAM role to authorize push. No need to validate URL. Cloud Run Service Cloud Pub/Sub IAM: role: "roles/run.invoker" member: "serviceAccount:pubsub@..." gcloud alpha pubsub subscriptions create my-sub --topic my-topic --push-endpoint=https://service.run.app --push-auth-service-account=pubsub@...
  45. Async tasks Cloud Tasks HTTP targets (Beta soon) push to

    Cloud Run URL with authentication token Leverage "Invoker" IAM role. Service Cloud Tasks IAM: role: "roles/run.invoker" member: "serviceAccount:tasks@..." HTTP target
  46. Scheduled services Cloud Scheduler with authentication token Leverage "Invoker" IAM

    role. Service Cloud Scheduler IAM: role: "roles/run.invoker" member: "serviceAccount:scheduler@..."
  47. Concurrency Each Service is autoscaled to many container instances. Concurrency

    = "maximum number of requests that can be sent at the same time to a given container instance" AWS Lambda or Google Cloud Functions: only one request at a time to each instance, "concurrency = 1". With Cloud Run: set concurrency value from 1 to 250 (default: 80) → optimized resource consumption → optimized costs concurrency = 1 concurrency = 80
  48. Proprietary + Confidential Google Cloud Serverless Compute Product Portfolio App

    Engine Cloud Run Cloud Functions Event-driven Functions-as-a-Service Run containers on a fully managed environment Run source-based web applications on a fully managed environment
  49. Proprietary + Confidential Serverless Use Cases App Engine Cloud Run

    Cloud Functions Build a web app Web app Request-based services Developing APIs Web & mobile backends Internal APIs and services Data Processing Automation Workflow & Orchestration Event driven reactive automation Connecting Cloud Services Best use cases for Serverless compute products More at https://cloud.run