Bird
Raised Fist0
GCPcloud~5 mins

Serverless vs GKE decision in GCP - CLI Comparison

Choose your learning style10 modes available
Introduction
Choosing between serverless and Google Kubernetes Engine (GKE) helps you decide how to run your app. Serverless lets you run code without managing servers, while GKE gives you control over containers and infrastructure.
When you want to quickly run small apps or functions without worrying about servers or scaling.
When you need full control over containerized apps and want to manage scaling and updates yourself.
When your app has unpredictable traffic and you want automatic scaling without manual setup.
When you have complex apps that need multiple containers working together with custom networking.
When you want to reduce operational work and pay only for the exact compute time your code uses.
Commands
Deploys a container image to Cloud Run, which is a serverless platform. This runs your app without managing servers and scales automatically.
Terminal
gcloud run deploy my-serverless-app --image=gcr.io/my-project/my-image --region=us-central1 --platform=managed
Expected OutputExpected
Deploying container to Cloud Run service [my-serverless-app] in project [my-project] region [us-central1] Done. Service [my-serverless-app] revision [my-serverless-app-00001-abc] has been deployed and is serving traffic at https://my-serverless-app-abc.a.run.app
→
--image - Specifies the container image to deploy
→
--region - Sets the region where the service runs
→
--platform - Chooses the managed serverless platform
Grants your Google account admin rights on the GKE cluster so you can manage resources.
Terminal
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value account)
Expected OutputExpected
clusterrolebinding.rbac.authorization.k8s.io/cluster-admin-binding created
Creates a GKE cluster with 3 nodes in the specified zone. This cluster lets you run and manage containerized apps with control over infrastructure.
Terminal
gcloud container clusters create my-gke-cluster --zone us-central1-a --num-nodes 3
Expected OutputExpected
Creating cluster my-gke-cluster in us-central1-a... Created [https://container.googleapis.com/v1/projects/my-project/zones/us-central1-a/clusters/my-gke-cluster]. To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/my-gke-cluster?project=my-project kubeconfig entry generated for my-gke-cluster NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS my-gke-cluster us-central1-a 1.26.8-gke.100 35.233.123.45 e2-medium 1.26.8-gke.100 3 RUNNING
→
--zone - Specifies the zone for the cluster
→
--num-nodes - Sets the initial number of nodes
Lists the nodes in your GKE cluster to verify the cluster is ready and nodes are running.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION my-gke-cluster-default-pool-1a2b3c4d-5e6f RUNNING <none> 2m v1.26.8-gke.100
Key Concept

If you remember nothing else from this pattern, remember: serverless is best for simple, auto-scaling apps without server management, while GKE is best when you need full control over containerized apps and infrastructure.

Common Mistakes
Trying to deploy a complex multi-container app directly to Cloud Run without splitting it into services.
Cloud Run is designed for single container services and does not support multi-container pods like Kubernetes.
Use GKE for multi-container apps or split your app into multiple Cloud Run services.
Creating a GKE cluster without setting up proper permissions for kubectl access.
Without cluster-admin binding, you cannot manage resources on the cluster.
Run the clusterrolebinding command to grant your user admin rights on the cluster.
Deploying serverless apps in a region far from your users causing latency.
Serverless apps scale automatically but latency depends on region proximity.
Choose a region close to your users when deploying Cloud Run services.
Summary
Deploy serverless apps with 'gcloud run deploy' for easy scaling and no server management.
Create GKE clusters with 'gcloud container clusters create' to run complex containerized apps with control.
Use 'kubectl' commands to manage and verify your GKE cluster nodes and permissions.

Practice

(1/5)
1. Which option best describes a key benefit of using serverless computing in GCP?
easy
A. No need to manage servers and automatic scaling happens
B. You get full control over the underlying hardware
C. You must manually configure load balancers
D. You need to manage container orchestration

Solution

  1. Step 1: Understand serverless basics

    Serverless means the cloud provider handles server management and scaling automatically.
  2. Step 2: Compare options

    The other options describe manual management or container orchestration, which are not serverless benefits.
  3. Final Answer:

    No need to manage servers and automatic scaling happens -> Option A
  4. Quick Check:

    Serverless = No server management + auto scaling [OK]
Hint: Serverless means no servers to manage, auto scales itself [OK]
Common Mistakes:
  • Confusing serverless with container management
  • Thinking serverless requires manual scaling
  • Assuming serverless means full hardware control
2. Which of the following is the correct way to deploy a containerized app on GKE?
easy
A. Use gcloud run deploy command
B. Use kubectl apply -f deployment.yaml command
C. Use firebase deploy command
D. Use gsutil cp to upload container image

Solution

  1. Step 1: Identify GKE deployment command

    GKE uses Kubernetes commands like kubectl apply to deploy resources from YAML files.
  2. Step 2: Check other commands

    gcloud run deploy is for serverless Cloud Run, firebase deploy is for Firebase apps, and gsutil cp uploads files to storage, not deploy containers.
  3. Final Answer:

    Use kubectl apply -f deployment.yaml command -> Option B
  4. Quick Check:

    GKE deploy = kubectl apply [OK]
Hint: GKE uses kubectl with YAML files to deploy containers [OK]
Common Mistakes:
  • Using Cloud Run commands for GKE
  • Confusing Firebase deploy with container deployment
  • Uploading images with gsutil instead of container registry
3. You have a web app with unpredictable traffic spikes and want minimal management. Which GCP service behavior fits best?
medium
A. Serverless auto-scales instantly with no server management
B. GKE requires manual scaling and cluster management
C. GKE automatically scales without any configuration
D. Serverless requires you to provision VM instances

Solution

  1. Step 1: Analyze traffic and management needs

    Unpredictable spikes need fast scaling and minimal management.
  2. Step 2: Match service behavior

    Serverless auto-scales instantly and requires no server management. GKE needs manual or configured scaling and cluster upkeep.
  3. Final Answer:

    Serverless auto-scales instantly with no server management -> Option A
  4. Quick Check:

    Unpredictable traffic + minimal management = Serverless [OK]
Hint: Unpredictable traffic? Choose serverless for auto scaling [OK]
Common Mistakes:
  • Assuming GKE scales automatically without config
  • Thinking serverless needs VM provisioning
  • Confusing manual and automatic scaling
4. You deployed a container on GKE but it fails to start. Which fix is most likely needed?
medium
A. Enable serverless API in GCP console
B. Increase Cloud Run memory allocation
C. Check and fix container image path in deployment YAML
D. Upload container image to Firebase hosting

Solution

  1. Step 1: Identify cause of container start failure

    Common cause is incorrect container image path or tag in deployment YAML.
  2. Step 2: Evaluate options

    Increasing Cloud Run memory or enabling serverless API does not affect GKE container start. Firebase hosting is unrelated to container images.
  3. Final Answer:

    Check and fix container image path in deployment YAML -> Option C
  4. Quick Check:

    Container start fail? Fix image path in YAML [OK]
Hint: Check container image path in YAML if GKE pod fails [OK]
Common Mistakes:
  • Trying serverless fixes for GKE issues
  • Uploading images to wrong services
  • Ignoring deployment YAML errors
5. Your app needs custom networking, persistent storage, and runs long background jobs. Which GCP choice fits best?
hard
A. Use serverless Cloud Run for easy scaling and no management
B. Use Firebase hosting for backend processing
C. Use App Engine standard environment for background jobs
D. Use GKE for full control over networking and storage

Solution

  1. Step 1: Identify app requirements

    Custom networking, persistent storage, and long background jobs require control and flexibility.
  2. Step 2: Match requirements to GCP services

    GKE offers container orchestration with networking and storage control. Serverless Cloud Run lacks persistent storage and complex networking. App Engine standard has limitations on background jobs. Firebase hosting is for static content.
  3. Final Answer:

    Use GKE for full control over networking and storage -> Option D
  4. Quick Check:

    Custom network + storage + long jobs = GKE [OK]
Hint: Need control and storage? Choose GKE over serverless [OK]
Common Mistakes:
  • Choosing serverless despite storage needs
  • Using App Engine for heavy background jobs
  • Confusing Firebase hosting with backend services
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard