Deploying .NET 10 Web APIs to Google Cloud Run: A Cost-Optimization Guide

Meta Description: Learn how to deploy .NET 10 Web APIs to Google Cloud Run with cost optimization tips. Step-by-step guide for serverless, scalable, and budget-friendly deployments....

By Ajith joseph · Mon Jul 13 2026 · Updated Mon Jul 13 2026 · 7 min read · intermediate

#api #net #run #your #cloud

Meta Description: Learn how to deploy .NET 10 Web APIs to Google Cloud Run with cost optimization tips. Step-by-step guide for serverless, scalable, and budget-friendly deployments.


Introduction

Deploying .NET 10 Web APIs to the cloud doesn’t have to break the bank. With Google Cloud Run, you can enjoy the benefits of serverless architecture—scalability, flexibility, and reduced operational overhead—while keeping costs under control. This guide will walk you through the entire process of deploying your .NET 10 Web API to Cloud Run and share cost-optimization strategies to maximize your budget.

Whether you're a developer, DevOps engineer, or tech enthusiast, this step-by-step guide will help you:

  • Understand why Cloud Run is an excellent choice for .NET 10 Web APIs.
  • Deploy your API with Docker and Cloud Run.
  • Optimize costs without sacrificing performance.

Let’s dive in!


Why Choose Google Cloud Run for .NET 10 Web APIs?

Google Cloud Run is a serverless platform that automatically scales your applications in response to demand. It’s an ideal choice for deploying .NET 10 Web APIs for several reasons:

1. Serverless Benefits

  • No Infrastructure Management: Cloud Run handles the underlying infrastructure, so you can focus on writing code.
  • Automatic Scaling: Scale to zero when there’s no traffic, and scale up instantly during peak loads.
  • Pay-per-Use Pricing: You only pay for the resources you consume, making it cost-effective for low-to-medium traffic applications.

2. Seamless Integration with .NET 10

  • .NET 10 is optimized for containerized deployments, and Cloud Run is designed to run containers effortlessly.
  • Supports custom Docker images, allowing you to tailor your environment to your API’s needs.

3. Cost Efficiency

  • No Idle Costs: Unlike traditional virtual machines, Cloud Run charges you only when your API is handling requests.
  • Free Tier: Google Cloud offers a generous free tier, which is perfect for small projects or testing.

4. Fast Deployment and Iteration

  • Deploy updates in seconds with continuous integration/continuous deployment (CI/CD) pipelines.
  • Integrate with Cloud Build for automated deployments.

Step-by-Step Deployment Guide

Deploying your .NET 10 Web API to Cloud Run involves a few key steps. Follow this guide to get your API up and running in no time.


Prerequisites

Before you begin, ensure you have the following:

  • A Google Cloud Platform (GCP) account. Sign up here if you don’t have one.
  • Google Cloud SDK installed on your local machine. Download it here.
  • .NET 10 SDK installed. Download it here.
  • Docker installed for building container images. Download it here.
  • A project created in the Google Cloud Console with Cloud Run API enabled.

Configuring Your .NET 10 Web API for Cloud Run

To deploy your .NET 10 Web API to Cloud Run, it must be containerized using Docker. Here’s how to prepare your API:

1. Create a .NET 10 Web API

If you don’t already have a .NET 10 Web API, create one using the following command:

dotnet new webapi -n MyWebApi
cd MyWebApi

2. Add a Dockerfile

Create a Dockerfile in the root directory of your project with the following content:

# Use the official .NET 10 SDK image to build the application
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app

# Use the ASP.NET runtime image to run the application
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "MyWebApi.dll"]

3. Test Locally

Build and run your Docker image locally to ensure everything works:

docker build -t mywebapi .
docker run -p 8080:80 mywebapi

Visit http://localhost:8080/weatherforecast to test your API.


Building and Pushing a Docker Image

Now that your API is containerized, it’s time to push it to Google Container Registry (GCR).

1. Authenticate with Google Cloud

Run the following command to authenticate your Docker client with GCR:

gcloud auth configure-docker

2. Build and Tag Your Docker Image

Build your Docker image and tag it for GCR:

docker build -t gcr.io/[PROJECT-ID]/mywebapi:v1 .

Replace [PROJECT-ID] with your GCP project ID.

3. Push the Image to GCR

Push your Docker image to GCR:

docker push gcr.io/[PROJECT-ID]/mywebapi:v1

Deploying to Cloud Run

With your Docker image in GCR, you’re ready to deploy to Cloud Run.

1. Deploy Using the Google Cloud Console

  1. Open the Cloud Run console.
  2. Click Create Service.
  3. Select the Docker image you pushed to GCR.
  4. Configure the service:
    • Service Name: Enter a name for your service (e.g., mywebapi).
    • Region: Choose a region close to your users.
    • Memory Allocation: Start with 512MB (adjust based on your API’s needs).
    • CPU Allocation: Select CPU always allocated for better performance or CPU only during requests for cost savings.
    • Autoscaling: Set the minimum and maximum number of instances. For cost optimization, set the minimum to 0.
  5. Click Create to deploy your API.

2. Deploy Using the gcloud CLI

Alternatively, deploy using the gcloud command:

gcloud run deploy mywebapi \
  --image gcr.io/[PROJECT-ID]/mywebapi:v1 \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --memory 512Mi \
  --cpu 1

Testing Your Deployment

Once your API is deployed, Cloud Run will provide a URL. Test it using:

curl https://mywebapi-[HASH].a.run.app/weatherforecast

Replace [HASH] with the unique identifier in your Cloud Run URL.


Cost-Optimization Strategies for Cloud Run

Deploying to Cloud Run is cost-effective, but there are ways to optimize your spending further. Here are some cost-optimization strategies for your .NET 10 Web API:


1. Right-Size Your Resources

  • Memory Allocation: Start with 512MB and adjust based on your API’s performance. Use Cloud Monitoring to track memory usage.
  • CPU Allocation: Choose CPU only during requests to save costs if your API doesn’t require background processing.

2. Leverage Autoscaling

  • Set the minimum number of instances to 0 to avoid paying for idle resources.
  • Configure the maximum number of instances to control costs during traffic spikes.

3. Use Request Timeouts

  • Set a request timeout (e.g., 5 minutes) to prevent long-running requests from consuming resources unnecessarily.

4. Monitor and Optimize Performance

  • Use Cloud Monitoring and Cloud Logging to track performance and identify bottlenecks.
  • Optimize your .NET 10 Web API code to reduce execution time and resource usage.

5. Take Advantage of the Free Tier

  • Google Cloud offers a free tier for Cloud Run, including:
    • 2 million requests per month.
    • 360,000 GB-seconds of memory per month.
    • 180,000 vCPU-seconds per month.

6. Use Custom Domains Wisely

  • If you’re using a custom domain, ensure it’s properly configured to avoid unnecessary redirects or SSL certificate costs.

7. Implement CI/CD for Efficient Deployments

  • Use Cloud Build to automate deployments and reduce manual errors.
  • Implement blue-green deployments to minimize downtime and ensure smooth updates.

Conclusion

Deploying your .NET 10 Web API to Google Cloud Run is a smart choice for developers looking to balance performance, scalability, and cost efficiency. By following this guide, you’ve learned how to:

  1. Containerize your .NET 10 Web API using Docker.
  2. Deploy your API to Cloud Run using the Google Cloud Console or gcloud CLI.
  3. Optimize costs with strategies like right-sizing resources, leveraging autoscaling, and monitoring performance.

Now it’s your turn to put these steps into action! Start by deploying your .NET 10 Web API to Cloud Run and explore the cost-saving features it offers.


Call to Action

Ready to deploy your .NET 10 Web API to Google Cloud Run? Get started today and experience the benefits of serverless architecture. Share your experience in the comments or explore more resources on Google Cloud’s documentation. Happy coding! 🚀

  1. AJ's Tech Notes
  2. Deploying .NET 10 Web APIs to Google Cloud Run: A Cost-Optimization Guide