Skip to content

Intermediate · Containers in the cloud · topic 34 of 50 · 25 min

Choosing where to run a container

Explanation

You can run a container on serverless container platforms (Cloud Run, Azure Container Apps, ECS on Fargate), on managed Kubernetes, on plain VMs, or on a PaaS such as Azure App Service or AWS Elastic Beanstalk. Start with the simplest option your team can run well, and move to Kubernetes when the number of services, the team's skills and the need for control justify it.

Many ways to run the same image

Once your app is a container image, you have choices. The image does not change; what changes is how much the cloud manages for you, how you pay, and how much control you have. More control usually means more work. The right answer depends on your team and your traffic more than on technology fashion.

OptionExamplesYou manageBest when
Serverless containersCloud Run, Azure Container Apps, ECS on FargateThe image and a few settingsSmall teams, web APIs, spiky or low traffic
Managed KubernetesEKS, AKS, GKEManifests, add-ons, upgrades, often nodesMany services, platform skills, need for Kubernetes tools
Plain VMsEC2, Azure VMs, Compute EngineThe operating system, Docker, patching, scalingSpecial OS needs, licensed software, very simple single servers
PaaSAzure App Service, AWS Elastic BeanstalkThe code or image and app settingsClassic web apps, teams that want a managed platform without Kubernetes

Serverless containers in more detail

Cloud Run and Azure Container Apps scale on incoming requests and can scale to zero, so a service with no traffic costs little or nothing. The trade-off is a cold start: the first request after a quiet period waits while a container starts. If that delay matters, keep a minimum number of instances warm, which costs some money all the time.

ECS on Fargate is also serverless in the sense that you manage no servers, but a service keeps its desired number of tasks running all the time. It does not wake up on a request the way Cloud Run does. You can scale it with metrics or schedules, including down to zero tasks at night.

bash
gcloud run deploy orders-api --image asia-south1-docker.pkg.dev/shop-prod/apps/orders-api:1.0.0 --region asia-south1 --min-instances=1 --max-instances=20
Deploy to Cloud Run with one warm instance to avoid cold starts and a cap of 20 to limit cost.

Decision factors

  1. Team size and skills: Kubernetes needs people who understand networking, upgrades and its many tools. A team of three developers rarely has that time.
  2. Number of services: two or three services are easy anywhere. Thirty services with shared policies, service-to-service security and custom tooling start to benefit from Kubernetes.
  3. Traffic pattern: spiky or quiet traffic suits scale to zero. Steady, heavy traffic can be cheaper on reserved nodes.
  4. Scale to zero: needed for many small internal tools and test environments. Cloud Run and Container Apps do it natively.
  5. Cost: compare the whole bill, including load balancers, the Kubernetes control plane fee, idle capacity and the people time to run it.
  6. Portability: a container image runs anywhere. Kubernetes manifests move between clouds; Cloud Run settings do not, but they are small to rewrite.
Tip: A good rule: use the most managed option that meets your needs today. Moving a container from Cloud Run to GKE later is a few days of work, not a rewrite, because the image stays the same.

A Bengaluru startup grows up

A two-person startup in Bengaluru builds a home-services booking app. They have one API and one worker, little traffic at night and spikes on weekends. They choose Cloud Run in asia-south1: no servers, scale to zero overnight, and a monthly bill small enough to sit inside their credits. Deploys are one gcloud command from CI.

Two years later they have 20 engineers and 28 services, need network policies between services, a service mesh for mutual TLS, and background jobs with GPUs for image checks. Two engineers now specialise in the platform. They move to a regional GKE cluster in Autopilot mode, where the image-check jobs simply request GPUs in their pod specs. The same images are deployed with Kubernetes manifests. Simple, low-traffic internal tools stay on Cloud Run, because there is no reason to move them.

Careful: Common mistakes: choosing Kubernetes on day one because big companies use it (you pay in complexity before you get the benefits); forgetting cold starts with scale to zero (use a minimum instance count for user-facing paths); comparing only compute prices and ignoring load balancers, NAT and people time; and fearing lock-in so much that you avoid managed services that would save months. The container image is your portability.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Choosing where to run a container · 1/7

Same image Different platforms

The same container image can run in many places. The question is how much you want the cloud to manage.

Prefer a video by a teacher? Find free videos on “cloud run vs kubernetes vs fargate when to use which” on YouTube ↗

In real life: A government services portal in Lucknow

A state e-governance team in Lucknow runs a certificate application portal. Traffic is near zero at night and jumps at the start of each admission season. The team of four developers has no Kubernetes experience, and the department already uses Microsoft 365 and Azure. They choose Azure Container Apps in Central India: it scales on HTTP traffic, scales down when idle, and needs no cluster management. A legacy reporting tool that needs a specific Windows component stays on an Azure VM. They write down the decision and agree to review it if they grow beyond fifteen services.

Practice (0/3 done)

Task 1 · Question

A two-person team has one web API with almost no traffic at night and wants the lowest bill with no servers to manage. What is the best fit?

Task 2 · Code · Javascript

Write recommend(req) that returns where to run a workload. req has: needsOsControl (true/false), containerised (true/false), services (a number) and kubernetesSkills (true/false). Apply these rules in order: (1) if needsOsControl, return "virtual-machines"; (2) if the app is not containerised, return "paas"; (3) if services is 10 or more AND the team has Kubernetes skills, return "managed-kubernetes"; (4) otherwise return "serverless-containers".

Task 3 · Practice

Write a short decision record (half a page) for one of these: (a) a college fest website that gets heavy traffic for one week a year; (b) a hospital chain with 15 internal services, a 6-person platform team and strict uptime needs. Say which option you choose, which cloud service, and why, and name what would make you change the decision.

Quick quiz

Question 1

1.Which platform does NOT wake up on an incoming request from zero instances?

Question 2

2.What is the main downside of scale to zero for a user-facing API?

Question 3

3.When is managed Kubernetes usually worth its extra complexity?

Question 4

4.A team moves an app from Cloud Run to GKE. What usually stays the same?

Question 5

5.Which is a PaaS option that can run web apps from code or containers without Kubernetes?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which platform does NOT wake up on an incoming request from zero instances?

Answer: An ECS service on Fargate

An ECS service keeps its desired task count running; it scales on metrics or schedules, not by waking on a request.

What is the main downside of scale to zero for a user-facing API?

Answer: Cold starts: the first request after a quiet period is slower

A new container must start; a minimum instance count avoids this at some cost.

When is managed Kubernetes usually worth its extra complexity?

Answer: For many services, with platform skills and a need for Kubernetes tools

Kubernetes pays off at scale and with the people to run it.

A team moves an app from Cloud Run to GKE. What usually stays the same?

Answer: The container image

The image is portable; the configuration around it changes.

Which is a PaaS option that can run web apps from code or containers without Kubernetes?

Answer: Azure App Service

Azure App Service (and AWS Elastic Beanstalk) are platforms as a service.

What does "managed control plane" mean in EKS, AKS and GKE?Related

Answer: The provider runs, patches and keeps the control plane available; you manage workloads

The provider operates the control plane; your Deployments, Services and usually nodes remain yours.

From Managed Kubernetes: EKS, AKS and GKE

When would the EC2 launch type make more sense than Fargate?Related

Answer: For a steady, heavy workload that needs GPUs or special instance types

The EC2 launch type gives you control of instance types such as GPUs, and can be cheaper for steady, tightly packed load.

From Amazon ECS and AWS Fargate

What does "serverless" really mean?Related

Answer: You do not manage the servers; the provider does

Servers still exist. You just never see, size or patch them, and you pay per use.

From IaaS, PaaS, SaaS and serverless

Which service runs your container, scales with traffic and can scale down to zero?Related

Answer: Cloud Run

Cloud Run is serverless containers with scale to zero.

From Core Google Cloud services

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. This is the last topic of “Containers in the cloud”. The module exam comes next.
  2. Module 8 exam: Containers in the cloud · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
  3. Then the next module, Infrastructure as code. 50 topics left in the course before the final exam.

← Previous: Managed Kubernetes: EKS, AKS and GKE