Building Serverless Applications with Google Cloud Run: A Real-World Guide to Building Production-Ready Services

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn how to build a real-world serverless application in the cloud that's reliable, secure, maintainable, and scalable. If you have experience building web applications on traditional infrastructure, this hands-on guide shows you how to get started with Cloud Run, a container-based serverless product on Google Cloud. Through the course of this book, you'll learn how to deploy several example applications that highlight different parts of the serverless stack on Google Cloud. Combining practical examples with fundamentals, this book will appeal to developers who are early in their learning journey as well as experienced practitioners. • Build a serverless application with Google Cloud Run • Learn approaches for building containers with (and without) Docker • Explore Google Cloud's managed relational database: Cloud SQL • Use HTTP sessions to make every user's experience unique • Explore identity and access management (IAM) on Cloud Run • Provision Google Cloud resources using Terraform • Learn how to handle background task scheduling on Cloud Run • Move your service from Cloud Run to Knative Serving with little effort

Author(s): Wietse Venema
Edition: 1
Publisher: O'Reilly Media
Year: 2020

Language: English
Commentary: Vector PDF
Pages: 202
City: Sebastopol, CA
Tags: Google Cloud Platform; Web Applications; Relational Databases; Logging; Docker; Containerization; Google Cloud SQL; Terraform; Serverless Applications; Task Scheduling; Knative

Cover
Copyright
Table of Contents
Foreword
Preface
Why I Wrote This Book
Who This Book Is For
Why Use the Go Language?
Navigating This Book
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
Chapter 1. Introduction
Serverless Applications
A Simple Developer Experience
Autoscalable Out of the Box
A Different Cost Model
Serverless Is Not Functions as a Service
Google Cloud
Serverless on Google Cloud
Cloud Run
Service
Container Image
Scalability and Self-Healing
HTTPS Serving
Microservices Support
Identity, Authentication, and Access Management
Monitoring and Logging
Transparent Deployments
Pay-Per-Use
Concerns About Serverless
Unpredictable Costs
Hyper-Scalability
When Things Go Really Wrong
Separation of Compute and Storage
Open Source Compatibility
Summary
Chapter 2. Understanding Cloud Run
Getting Started with Google Cloud
Costs
Interacting with Google Cloud
Google Cloud Projects
Installing and Authenticating the SDK
Installing Beta Components
Deploying Your First Service
Deploying the Sample Container
Region
Structure of the HTTPS Endpoint
Viewing Your Service in the Web Console
Deploying a New Version
Revision
Understanding Cloud Run
Container Life Cycle
CPU Throttling
Task Scheduling and Throttling
Load Balancer and Autoscaler
Concurrent Request Limit
Autoscaler
Tuning the Concurrency Setting
Cold Starts
Disposable Containers
In-Memory Filesystem
Ready for Requests
Cloud Run Key Points
Choosing a Serverless Compute Product on Google Cloud
Cloud Functions: Glue Code
App Engine: Platform as a Service
Key Differences
What Will the Future Look Like?
Summary
Chapter 3. Building Containers
Containers: A Hands-On Exploration
Running an Interactive Shell
Overriding the Default Command
Running a Server
Containers from First Principles
Inside a Container Image
The Linux Kernel
Container Isolation
Starting a Container
Building a Container with Docker
Dockerfile Instructions
Installing Additional Tooling
Smaller Is Better When Deploying to Production
Creating Small Containers with Distroless
Artifact Registry
Building and Tagging the Container Image
Authenticating and Pushing the Container Image
Building a Container Without a Dockerfile
Go Containers with ko
Java Containers with Jib
Cloud Native Buildpacks
Cloud Build
Remote Docker Build
Advanced Builds
Running Arbitrary Programs
Connecting with Version Control
Shutting Down
Summary
Chapter 4. Working with a Relational Database
Introducing the Demo Application
Creating the Cloud SQL Instance
Understanding Cloud SQL Proxy
Connecting and Loading the Schema
Securing the Default User
Connecting Cloud Run to Cloud SQL
Disabling the Direct Connection
Deploying the Demo Application
Connection String
Public and Private IP
Limiting Concurrency
Transaction Concurrency
Resource Contention
Scaling Boundaries and Connection Pooling
External Connection Pool
A Real-World Example
Cloud SQL in Production
Monitoring
Automatic Storage Increase
High Availability
Making Your Application Resilient Against Short Downtime
Shutting Down
Summary
Chapter 5. Working with HTTP Sessions
How HTTP Sessions Work
Storing Sessions in Memorystore: A Hands-On Exploration
Creating a Memorystore Instance
What Is a VPC Connector?
Creating a VPC Connector
Deploying the Demo App
Alternative Session Stores
Session Affinity
Use Cases
Session Affinity Is Not for Session Data
Shutting Down
Summary
Chapter 6. Service Identity and Authentication
Cloud IAM Fundamentals
Roles
Policy Binding
Service Accounts
Creating and Using a New Service Account
Sending Authenticated Requests to Cloud Run
Deploying a Private Service
Using an ID Token to Send Authenticated Requests
When Is an ID Token Valid?
Programmatically Calling Private Cloud Run Services
Google Frontend Server
A Story About Inter-Service Latency
Demo Application
Embedded Read-Only SQL Database
Running Locally
Edit, Compile, Reload
Deploying to Cloud Run
Update the Frontend Configuration
Add Custom Service Accounts
Add IAM Policy Binding
Summary
Chapter 7. Task Scheduling
Cloud Tasks
Hands-On Learning: A Demo Application
Building the Container Images
Creating a Cloud Tasks Queue
Creating Service Accounts
Deploying the Worker Service
Deploying the Task App Service
Connecting the Task Queue
Scheduling a Task with the Cloud Tasks Client Library
Automatic ID Token
Connecting the Worker
Test the App
Queue Configuration
Retry Configuration
Rate Limiting
Viewing and Updating Queue Configuration
Considerations
Cloud Tasks Might Deliver Your Request Twice
Local Development
Alternatives
Summary
Chapter 8. Infrastructure as Code Using Terraform
What Is Infrastructure as Code?
Why Infrastructure as Code?
Serverless Infrastructure
How It Works
When Not to Use Infrastructure as Code
Terraform
Installing Terraform
Getting Started with a Minimal Example
The Terraform Workflow
Change with Terraform: Adding the Access Policy
Expressing Dependencies with References
Supplemental Resources
Summary
Chapter 9. Structured Logging and Tracing
Logging on Cloud Run
Viewing Logs in the Web Console
Viewing Logs in the Terminal
Finding Invisible Logs
Plain-Text Logs Leave You Wanting More
Demo Application
Structured Logging
Client Libraries
Structured Logging in Other Languages
How to Use Log Levels
Capturing Panics
Local Development
Request Context
Trace Context
Forwarding Trace ID
Preparing All Incoming Requests with the Trace ID
Passing Request Context to Outgoing Requests
Viewing Trace Context in Cloud Logging
Additional Resources About Tracing
Log-Based Metrics with Cloud Monitoring
Summary
Chapter 10. Cloud Run and Knative Serving
What Is Knative Serving?
Cloud Run Is Not Managed Knative Serving
Knative Serving on Google Cloud
Understanding Kubernetes
API Server
Kubernetes Resources
Database
Controllers
Adding Extensions to Kubernetes
Running Knative Serving Locally
Running a Local Kubernetes Cluster
Installing Minikube and kubectl
Starting Your Local Cluster
Install the Knative Operator
Starting Minikube Tunnel
Installing an HTTP Load Balancer
Configuring DNS
Deploying a Service
Deploying the Same Service to Cloud Run
Alternative API Clients
Shutting Down
Discussion
Serving
Moving from Kubernetes to Cloud Run Is Harder
Service Identity and Authentication
Proprietary Managed Services
Summary
Index
About the Author
Colophon