GCP - Professional Cloud Developer Study Guide

    3: Configuring cloud-native applications for deployment

    This chapter takes the signed, attested container images produced by the Cloud Build pipelines of Chapter 2 and turns them into running production deployments on Cloud Run and Google Kubernetes Engine. It covers source-to-Cloud-Run pipelines, revision tagging and traffic splitting, Eventarc and Pub/Sub trigger wiring, Apigee API versioning and security, GKE Deployment manifests, liveness and readiness and startup probes, and Horizontal Pod Autoscaler tuning with CPU, memory, custom, and external metrics under v2 behavior policies.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Deploy applications to Cloud Run from source code using gcloud run deploy --source and from prebuilt images, and choose between deploy modes based on build, security, and reproducibility constraints.
    • Wire Cloud Run services as event receivers for Eventarc triggers (Cloud Storage, Audit Logs, Pub/Sub) and Pub/Sub push subscriptions, including OIDC service-account-based authentication and dead-letter routing.
    • Configure event receivers using CloudEvents headers, signed event payloads, and per-event idempotency keys, and tune the deploy-time knobs that control retry semantics.
    • Version, expose, and secure REST and gRPC APIs through Apigee API products, environments, and policies, including OAuth 2.0, JWT verification, Spike Arrest, and quota enforcement.
    • Deploy containerized applications to GKE with Deployment, Service, and Ingress manifests under Autopilot and Standard, and apply rolling update strategies that respect surge and unavailability budgets.
    • Implement Kubernetes health checks across liveness, readiness, and startup probes with HTTPGet, TCPSocket, gRPC, and Exec actions, and pick the right probe shape for slow-starting and degraded workloads.
    • Configure the Horizontal Pod Autoscaler v2 with CPU and memory utilization targets, custom Pod metrics, external metrics from Pub/Sub or Cloud Monitoring, and per-direction behavior policies that govern scale velocity and stabilization windows.

    Executive Summary

    • Cloud Run deployment is a two-decision exercise: pick the source (source code via buildpacks, or a prebuilt Artifact Registry image) and pick the revision routing (immediate cut-over, blue-green via --tag, or weighted split via --to-revisions). Both decisions are independent of the runtime tuning levers (--min-instances, --no-cpu-throttling, --concurrency) covered in Chapter 1.
    • Event receivers on Cloud Run come in two shapes. Eventarc delivers CloudEvents with structured headers for Cloud Storage, Audit-Log-filtered, Pub/Sub, and third-party providers; Pub/Sub push subscriptions deliver raw envelope-wrapped messages. Both authenticate to the receiver with an OIDC token from a delivery service account that holds roles/run.invoker.
    • Apigee fronts Cloud Run and GKE services with API products grouped by lifecycle environment, with OAuth 2.0 and JWT verification at the proxy, Spike Arrest and Quota policies for rate control, and Revision-numbered proxy bundles for safe rollouts that route through environment-attached deployments.
    • GKE deployment uses Deployment, ReplicaSet, Service, and Ingress resources, applied through kubectl apply -f against a context obtained with gcloud container clusters get-credentials. Autopilot accepts a narrower set of pod specs (no DaemonSets requiring privileged hostPath, restricted Linux capabilities), Standard accepts the full Kubernetes surface in exchange for explicit node-pool management.
    • Probe selection on GKE is workload-shape-driven: HTTPGet for HTTP services with a cheap health endpoint, gRPC probes for gRPC services (grpc: action), TCPSocket for non-HTTP TCP listeners, and Exec for sidecar checks. A startupProbe protects slow-booting JVM and ML services from a too-aggressive liveness loop; readinessProbe alone removes a degraded pod from the Service endpoint pool without restarting it.
    • HPA v2 (autoscaling/v2) accepts CPU, memory, Pods, Object, and External metrics, plus a behavior block with scaleUp and scaleDown policies that bound scale velocity and add stabilization windows. Custom Pods metrics flow through the Custom Metrics Stackdriver Adapter; external metrics flow through the External Metrics Adapter against Cloud Monitoring time series like Pub/Sub num_undelivered_messages.

    Assumptions

    • The reader has the chapter-1 service-and-network design decisions in place: VPC, load balancer, IAM least-privilege service accounts, and a security perimeter.
    • The reader has chapter-2 outputs available: an Artifact Registry repository holding signed images, a Binary Authorization policy with attestors, and Cloud Build triggers that produce SLSA Build Level 3 provenance.
    • Examples use the project ID acme-payments-prod, region europe-west1, Artifact Registry repository payments, and service account payments-runtime@acme-payments-prod.iam.gserviceaccount.com. Naming is consistent across the chapter to make IAM and routing relationships traceable.
    • Regions are illustrative; production deployments select regions per the data-residency, latency, and cost requirements established in the chapter-1 organisation policy mapping.
    • All gcloud snippets target the gcloud CLI on its current canonical surface. gsutil is shown only where it is the supported tool; new-build storage operations use gcloud storage.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account