Deploy Django or Flask App on Google Cloud Run & SQL Free Tier — Complete Tutorial

In 2025, deploying a Django or Flask application on Google Cloud Free Tier has become easier than ever, thanks to services like Cloud Run, Cloud SQL, and App Engine. This guide will walk you through every step, from project setup to production deployment, with SSL, database integration, and CI/CD pipelines.
If you are searching for how to deploy Django app on Google Cloud Free Tier or how to host your Flask app on GCP without spending money, then this tutorial is for you. By the end, you’ll have a fully deployed application running on Google’s infrastructure — for free.
Why Choose Google Cloud Free Tier for Django/Flask Apps?
There are multiple cloud providers, but Google Cloud stands out for its developer-friendly free tier. Let’s see why:
Feature | Google Cloud Free Tier | Benefit for Django/Flask |
---|---|---|
Cloud Run | 2 million requests free/month | Deploy containerized apps with auto-scaling |
Cloud SQL | $300 credits usable | Managed PostgreSQL/MySQL for Django ORM |
App Engine | 28 free instance hours/day | Serverless hosting option for web apps |
Cloud Storage | 5 GB always free | Static files, media hosting |
Now, let’s jump into the deployment process.
Step 1: Setup Google Cloud Project
- Go to Google Cloud Console
- Create a new project (e.g.,
django-flask-gcp-demo
) - Enable billing (don’t worry, Free Tier credits will apply)
- Activate Cloud Run, Cloud SQL, and Container Registry APIs
# Authenticate Google Cloud SDK
gcloud auth login
# Set project
gcloud config set project django-flask-gcp-demo
Step 2: Prepare Your Django/Flask App
Before deploying, make sure your application is production-ready. For Django:
# Install requirements
pip install django gunicorn psycopg2-binary
# Create requirements.txt
pip freeze > requirements.txt
# Production settings
DEBUG = False
ALLOWED_HOSTS = ["*"]
For Flask:
# Install requirements
pip install flask gunicorn
# app.py (Flask Example)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from Flask on Google Cloud Run!"
if __name__ == "__main__":
app.run()
DEBUG=True
in Django before deploying to production.
Step 3: Containerize Your Application
Google Cloud Run requires a Docker container. Create a Dockerfile
:
# Dockerfile for Django/Flask
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
# For Django:
# CMD gunicorn myproject.wsgi:application --bind 0.0.0.0:$PORT
# For Flask:
CMD gunicorn app:app --bind 0.0.0.0:$PORT
Build and push the Docker image:
gcloud builds submit --tag gcr.io/$(gcloud config get-value project)/myapp
Step 4: Deploy on Cloud Run
- Deploy the container to Cloud Run
- Choose region (e.g.,
us-central1
) - Allow unauthenticated access
- Get your live HTTPS URL
gcloud run deploy myapp \
--image gcr.io/$(gcloud config get-value project)/myapp \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Step 5: Setup Cloud SQL (PostgreSQL/MySQL)
If your app uses a database, you’ll need Cloud SQL:
- Create Cloud SQL instance (PostgreSQL recommended)
- Set root password and database name
- Enable
Cloud SQL Auth Proxy
# Install SQL Proxy
curl -o cloud_sql_proxy https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64
chmod +x cloud_sql_proxy
# Run Proxy
./cloud_sql_proxy -dir=/cloudsql \
-instances=PROJECT:REGION:INSTANCE_ID
Update Django settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': '/cloudsql/PROJECT:REGION:INSTANCE_ID',
'USER': 'postgres',
'PASSWORD': 'your_password',
'NAME': 'mydb',
}
}
Step 6: SSL and Custom Domain
Cloud Run provides free HTTPS by default. But if you want your own domain:
- Go to Cloud Run service
- Click "Custom Domains"
- Map your domain (via Cloud DNS)
- SSL certificates auto-configure for free
Step 7: CI/CD with GitHub Actions
Automate deployment with GitHub Actions:
# .github/workflows/deploy.yml
name: Deploy to Cloud Run
on:
push:
branches: ["main"]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Build and Push
run: gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT }}/myapp
- name: Deploy
run: gcloud run deploy myapp --image gcr.io/${{ secrets.GCP_PROJECT }}/myapp --region us-central1 --allow-unauthenticated
If you’re also exploring other cloud providers, check out our guide on How to Deploy Next.js/React App on AWS Free Tier . It’s a perfect companion read for developers who want to compare Google Cloud Free Tier vs AWS Free Tier for modern app hosting.
Troubleshooting Common Issues
Django Static Files Not Loading
Use Whitenoise
or host static files on Cloud Storage.
Cloud SQL Connection Error
Check if you enabled Cloud SQL Auth Proxy and IAM permissions.
High Latency on Cloud Run
Enable minimum instances to reduce cold starts (may incur small cost).
Final Thoughts
Deploying a Django or Flask app on Google Cloud Free Tier in 2025 is not only cost-efficient but also scalable and production-ready. With Cloud Run and Cloud SQL, you can run real-world applications without worrying about infrastructure.
If you’re a developer, student, or startup founder, this method is ideal to test, launch MVPs, and even run small-scale production apps for free.