AI Skill Hub 推荐使用:n8n AI工作流自动化 是一款优质的AI工具。AI 综合评分 7.8 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
基于Google Cloud的开源n8n工作流自托管解决方案,帮助用户免费搭建企业级自动化平台,无需订阅费用和服务器运维。适合需要工作流自动化、成本敏感的开发团队和企业用户。
n8n AI工作流自动化 是一款基于 HCL 开发的开源工具,专注于 n8n、工作流自动化、谷歌云 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
基于Google Cloud的开源n8n工作流自托管解决方案,帮助用户免费搭建企业级自动化平台,无需订阅费用和服务器运维。适合需要工作流自动化、成本敏感的开发团队和企业用户。
n8n AI工作流自动化 是一款基于 HCL 开发的开源工具,专注于 n8n、工作流自动化、谷歌云 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/datawranglerai/self-host-n8n-on-gcr cd self-host-n8n-on-gcr # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 self-host-n8n-on-gcr --help # 基本运行 self-host-n8n-on-gcr [options] <input> # 详细使用说明请查阅文档 # https://github.com/datawranglerai/self-host-n8n-on-gcr
# self-host-n8n-on-gcr 配置说明 # 查看配置选项 self-host-n8n-on-gcr --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export SELF_HOST_N8N_ON_GCR_CONFIG="/path/to/config.yml"
n8n is brilliant for automating all those tedious tasks you'd rather not do manually. This setup uses:
Why self-host? Complete control over your automation workflows and data. No arbitrary execution limits. No wondering where your sensitive data is being stored. And with Cloud Run, you get the best of both worlds - the control of self-hosting with the convenience of not having to manage actual servers.
Before diving in, make sure you've got:
The command line approach might seem intimidating at first, but it means we can script the entire deployment process. And when you need to update or recreate your instance, you'll thank yourself for having everything in a reusable format.
gcloud services enable artifactregistry.googleapis.com gcloud services enable run.googleapis.com gcloud services enable sqladmin.googleapis.com gcloud services enable secretmanager.googleapis.com ```
These commands establish your project environment and enable the necessary Google Cloud APIs. We're turning on all the services we'll need upfront to avoid those annoying "please enable this API first" errors later.
Queue Mode requires: - The redis.googleapis.com and compute.googleapis.com APIs enabled - A VPC network in your project (the default auto-mode VPC is fine) - The VPC's Private Service Access peering range available (used by Cloud Memorystore)
Cloud Memorystore Redis instances are only reachable via a private VPC IP address — they have no public endpoint. Cloud Run connects to them through Direct VPC Egress, which routes private-range traffic (10.x.x.x, 172.16.x.x, 192.168.x.x) through the VPC while leaving public internet traffic on the normal path.
n8n needs a small startup delay when connecting to external databases to avoid a race condition during initialisation. There are two ways to handle this:
If you need custom startup logic or want detailed debugging output, use a custom Docker image. This approach gives you more control but requires building and maintaining your own image.
Create these two files in your working directory:
startup.sh:
```bash #!/bin/sh
gcloud auth configure-docker $REGION-docker.pkg.dev
docker build --platform linux/amd64 -t $REGION-docker.pkg.dev/$PROJECT_ID/n8n-repo/n8n:latest . docker push $REGION-docker.pkg.dev/$PROJECT_ID/n8n-repo/n8n:latest ```
We're explicitly building for linux/amd64 because Cloud Run doesn't support ARM architecture. This is particularly important if you're developing on an M1/M2 Mac - Docker will happily build an ARM image by default, which then fails mysteriously when deployed. Ask me how I know.
The moment of truth - let's deploy n8n. The command differs slightly depending on which approach you chose in Step 2.
First, get your Cloud SQL conection namne:
export SQL_CONNECTION=$(gcloud sql instances describe n8n-db --format="value(connectionName)")
gcloud run deploy n8n \
--image=docker.io/n8nio/n8n:latest \
--command="/bin/sh" \
--args="-c,sleep 5; n8n start" \
--platform=managed \
--region=$REGION \
--allow-unauthenticated \
--port=5678 \
--cpu=1 \
--memory=2Gi \
--min-instances=0 \
--max-instances=1 \
--no-cpu-throttling \
--set-env-vars="N8N_PORT=5678,N8N_PROTOCOL=https,DB_TYPE=postgresdb,DB_POSTGRESDB_DATABASE=n8n,DB_POSTGRESDB_USER=n8n-user,DB_POSTGRESDB_HOST=/cloudsql/$SQL_CONNECTION,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,N8N_USER_FOLDER=/home/node/.n8n,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true,N8N_ENDPOINT_HEALTH=health" \
--set-secrets="DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest" \
--add-cloudsql-instances=$SQL_CONNECTION \
--service-account=n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com
```bash
gcloud run deploy n8n \ --image=$REGION-docker.pkg.dev/$PROJECT_ID/n8n-repo/n8n:latest \ --platform=managed \ --region=$REGION \ --allow-unauthenticated \ --port=5678 \ --cpu=1 \ --memory=2Gi \ --min-instances=0 \ --max-instances=1 \ --no-cpu-throttling \ --set-env-vars="N8N_PATH=/,N8N_PORT=443,N8N_PROTOCOL=https,DB_TYPE=postgresdb,DB_POSTGRESDB_DATABASE=n8n,DB_POSTGRESDB_USER=n8n-user,DB_POSTGRESDB_HOST=/cloudsql/$SQL_CONNECTION,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,N8N_USER_FOLDER=/home/node,EXECUTIONS_PROCESS=main,EXECUTIONS_MODE=regular,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true,N8N_ENDPOINT_HEALTH=health" \ --set-secrets="DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest" \ --add-cloudsql-instances=$SQL_CONNECTION \ --service-account=n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com ```
After deployment, Cloud Run will provide a URL for your n8n instance. Note it down - you'll need it for the next steps.
gcloud run services update n8n \ --region=$REGION \ --update-env-vars="N8N_HOST=$(echo $SERVICE_URL | sed 's/https:\/\///'),N8N_WEBHOOK_URL=$SERVICE_URL,N8N_EDITOR_BASE_URL=$SERVICE_URL" ```
Without these variables, OAuth would fail with utterly unhelpful "redirect_uri_mismatch" errors that make you question your life choices. Setting them correctly means n8n can construct proper callback URLs during authentication flows.
For newer versions of n8n use WEBHOOK_URL instead of N8N_WEBHOOK_URL.
The steps above give you a solid single-process n8n deployment. For most personal and small-team setups, that's all you'll ever need. But if you start running many concurrent heavy workflows, or if you want to keep the editor responsive while long-running workflows execute in the background, Queue Mode is the answer.
Workers run the n8n worker command instead of n8n start. They do not serve public internet traffic — they poll Redis and connect to Cloud SQL.
gcloud run deploy n8n-worker \
--image=docker.io/n8nio/n8n:latest \
--command="/bin/sh" \
--args="-c,sleep 5; n8n worker" \
--platform=managed \
--region=$REGION \
--no-allow-unauthenticated \
--ingress=internal \
--port=5678 \
--cpu=1 \
--memory=2Gi \
--min-instances=1 \
--max-instances=3 \
--no-cpu-throttling \
--vpc-egress=private-ranges-only \
--network=default \
--subnet=default \
--set-env-vars="EXECUTIONS_MODE=queue,DB_TYPE=postgresdb,DB_POSTGRESDB_DATABASE=n8n,DB_POSTGRESDB_USER=n8n-user,DB_POSTGRESDB_HOST=/cloudsql/$SQL_CONNECTION,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,N8N_USER_FOLDER=/home/node/.n8n,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true,N8N_RUNNERS_ENABLED=true,QUEUE_BULL_REDIS_HOST=$REDIS_HOST,QUEUE_BULL_REDIS_PORT=$REDIS_PORT" \
--set-secrets="DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest,QUEUE_BULL_REDIS_PASSWORD=n8n-redis-auth:latest" \
--add-cloudsql-instances=$SQL_CONNECTION \
--service-account=n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com
Key worker settings explained:
| Setting | Value | Why |
|---|---|---|
--ingress=internal | internal | Workers receive no public HTTP traffic — internal only |
--no-allow-unauthenticated | — | Workers should not be publicly invokeable |
--min-instances=1 | 1 | At least one worker must always be running or queued jobs never start |
--no-cpu-throttling | — | Workers poll Redis continuously and need CPU between "requests" |
EXECUTIONS_MODE=queue | queue | Tells the worker process to pick up jobs from Redis |
```bash
docker build --platform linux/amd64 -t $REGION-docker.pkg.dev/$PROJECT_ID/n8n-repo/n8n:latest .
gcloud run services update n8n \ --image=$REGION-docker.pkg.dev/$PROJECT_ID/n8n-repo/n8n:latest \ --region=$REGION
```
This approach lets you test new versions before committing to them. Check the n8n GitHub releases page to see what's new before upgrading.
Thanks to a generous contribution from the community, there is now a Terraform configuration available to automate the entire deployment process described in this guide. This Terraform setup provisions all necessary Google Cloud resources including Cloud Run, Cloud SQL, Secret Manager, IAM roles, and Artifact Registry.
Using Terraform can simplify and speed up deployment, especially for those familiar with infrastructure as code. The Terraform files and a deployment script are included in the repository.
Clone the repository and navigate to terraform directory
git clone <your-repo-url>
cd <repo-name>/terraform
Initialize Terraform
terraform init
Review the planned changes
terraform plan [use with flag terraform plan -var-file=terraform.tfvars if you created the terraform.tfvars file]
Deploy the infrastructure.
For Option A (recommended - official image):
terraform apply [use with flag terraform apply -var-file=terraform.tfvars if you created the terraform.tfvars file]
For Option B (custom image):
terraform apply -var="use_custom_image=true"
Or in terraform.tfvars:
use_custom_image = true # Only if you want custom image
The Terraform configuration supports Queue Mode through a single feature flag. When enable_queue_mode = true, Terraform will additionally provision:
n8n-worker) with internal ingress and min 1 instanceredis.googleapis.com and compute.googleapis.com APIsterraform apply -var="enable_queue_mode=true"
terraform.tfvars:```hcl gcp_project_id = "your-project-id" enable_queue_mode = true
So you want to run n8n without the monthly subscription fees, keep your data under your own control, and avoid the headache of server maintenance? Google Cloud Run offers exactly that sweet spot - serverless deployment with per-use pricing. Let's build this thing properly.
This guide walks you through deploying n8n (that powerful workflow automation platform) on Google Cloud Run with PostgreSQL persistence. You'll end up with a fully functional system that scales automatically, connects to Google services via OAuth, and won't drain your wallet when idle.
🚀 Quick Start Option: Want to skip the manual setup? Jump to the Terraform Deployment Option section for a streamlined, automated deployment. The step-by-step guide below is valuable for understanding what's happening under the hood, but Terraform will handle all the heavy lifting for you!
This is the simplest approach - use n8n's official Docker image with a command override to add a 5-second startup delay. This pattern comes from n8n's own Kubernetes deployments and works perfectly on Cloud Run.
No additional files needed! You'll use command overrides when deploying (covered in Step 7).
echo "Database settings:" echo "DB_TYPE: $DB_TYPE" echo "DB_POSTGRESDB_HOST: $DB_POSTGRESDB_HOST" echo "DB_POSTGRESDB_PORT: $DB_POSTGRESDB_PORT" echo "N8N_PORT: $N8N_PORT"
The rest of this guide will show commands for both approaches where they differ.
If you're using Option A (official image), skip this step entirely and go straight to Step 4.
If you're using Option B (custom image), you'll need a place to store your custom container image:
```bash
Why --no-cpu-throttling? n8n does background processing (database connections, scheduled checks) that happens outside HTTP requests. With CPU throttling enabled, these background tasks get starved and can cause startup issues. This flag ensures n8n gets continuous CPU access, which actually works out cheaper due to eliminated per-request fees and lower CPU/memory rates. Thanks to the Google Cloud Run team for this insight.
Other important settings: - min-instances=0 and max-instances=1 means your service scales to zero when idle (saving money) but won't run multiple instances simultaneously (which can cause database conflicts with n8n) - CPU and memory allocation is sufficient for most workflows without excessive costs - The sleep 5 in Option A handles database initialization timing
| Setting | Option A (Official) | Option B (Custom) | Why Different? |
|---|---|---|---|
| Image | docker.io/n8nio/n8n:latest | Your custom image | Direct from n8n vs your registry |
| Command | --command="/bin/sh" --args="-c,sleep 5; n8n start" | Uses custom entrypoint | Sleep added via command vs built into script |
| N8N_PORT | 5678 | 443 | Direct port vs mapped through startup script |
| N8N_PATH | Not needed | / | Custom image can handle path prefixing |
Here's what all those environment variables do:
| Environment Variable | Option A Value | Option B Value | Description |
|---|---|---|---|
| N8N_PATH | Not needed | / | Base path where n8n will be accessible (custom image only) |
| N8N_PORT | 5678 | 443 | Port configuration (direct vs mapped) |
| N8N_PROTOCOL | https | https | Protocol used for external access |
| DB_TYPE | postgresdb | postgresdb | Must be exactly "postgresdb" (not postgresql) for proper database connection |
| N8N_USER_FOLDER | /home/node/.n8n | /home/node | Location for n8n data |
| EXECUTIONS_PROCESS | Not needed | main (deprecated) | Deprecated - remove in newer versions |
| EXECUTIONS_MODE | Not needed | regular (deprecated) | Deprecated - remove in newer versions |
| QUEUE_HEALTH_CHECK_ACTIVE | true | true | Critical for Cloud Run to verify container health |
| N8N_ENDPOINT_HEALTH | health | health | Renames the health endpoint from /healthz to /health. Required on Cloud Run because GCP intercepts all /healthz requests at the load-balancer level, returning 404 before the request reaches your container (causing the "Offline" badge in the editor). See [n8n issue #25656](https://github.com/n8n-io/n8n/issues/25656). |
Pay special attention to DB_TYPE. It must be "postgresdb" not "postgresql" - a quirk that's caused many deployment headaches. And don't explicitly set the PORT variable as Cloud Run injects this automatically.
Now we need to update the deployment with environment variables that tell n8n how to properly generate URLs for OAuth callbacks:
```bash
| Variable | Main Service | Worker | Description |
|---|---|---|---|
EXECUTIONS_MODE | queue | queue | Activates queue mode. Workers won't run without this. |
QUEUE_BULL_REDIS_HOST | Redis private IP | Redis private IP | Host of the Memorystore instance |
QUEUE_BULL_REDIS_PORT | 6379 | 6379 | Redis port (Memorystore default) |
QUEUE_BULL_REDIS_PASSWORD | (from secret) | (from secret) | AUTH string stored in Secret Manager |
QUEUE_HEALTH_CHECK_ACTIVE | true | true | Exposes the health endpoint — required by Cloud Run health checks. The path is controlled by N8N_ENDPOINT_HEALTH (see below). |
N8N_ENDPOINT_HEALTH | health | health | Path for the health endpoint. Set to health (not healthz) because Cloud Run intercepts /healthz at the load-balancer level. |
N8N_RUNNERS_ENABLED | not set | true | Enables the task runner subsystem on workers. **Do not set this on the main service in queue mode** — the main process doesn't execute workflows, and setting it here causes n8n to crash at startup before the HTTP server can come up. |
The simplest approach - just update the image tag:
Update to latest version:
gcloud run services update n8n \
--image=docker.io/n8nio/n8n:latest \
--region=$REGION
Or specify a version:
gcloud run services update n8n \
--image=docker.io/n8nio/n8n:latest:1.115.2 \
--region=$REGION
Cloud Run will pull the new image and deploy it automatically. Takes about 1-2 minutes.
If you're using Queue Mode, update the worker service too:
gcloud run services update n8n-worker \
--image=docker.io/n8nio/n8n:latest \
--region=$REGION
It's important that the main service and all workers run the same n8n version. Mixed versions in queue mode can cause queue protocol mismatches.
Sometimes you'll need to update environment variables rather than the container itself:
gcloud run services update n8n \
--region=$REGION \
--update-env-vars="NEW_VARIABLE=value,UPDATED_VARIABLE=new_value"
This is useful when you need to change configuration without rebuilding the container.
redis_tier = "BASIC" # or "STANDARD_HA" for production redis_memory_size_gb = 1 worker_min_instances = 1 worker_max_instances = 3 worker_cpu = "1" worker_memory = "2Gi"
gcloud services enable redis.googleapis.com
gcloud services enable compute.googleapis.com
Note: If you used Terraform for deployment, see the Terraform Troubleshooting section for deployment-specific issues.
When things inevitably go sideways, here are the most common issues and how to fix them:
DB_TYPE is set to "postgresdb" (not "postgresql")QUEUE_HEALTH_CHECK_ACTIVE is set to "true"EXECUTIONS_PROCESS=main and EXECUTIONS_MODE=regular environment variables as these are now deprecated in newer versionsN8N_HOST, N8N_PORT, and N8N_EDITOR_BASE_URL are correctly setN8N_PORT is set to 443 (not 5678) for external URL formattingDB_POSTGRESDB_HOST format for Cloud SQL connectionsWEBHOOK_URL instead of N8N_WEBHOOK_URL for newer n8n versionsN8N_PROXY_HOPS=1 as Cloud Run acts as a reverse proxyIf you're encountering issues with Terraform deployment, especially after a previous manual installation attempt or a failed Terraform run, you may need to clean up existing resources first.
Common scenarios requiring cleanup: - You followed the manual steps before discovering the Terraform option - A previous Terraform deployment timed out or lost connectivity mid-build - You're seeing "resource already exists" errors
Clean up steps:
cd terraform/
rm -rf terraform.tfstate*
rm -rf .terraform/
Artifact Registry:
gcloud artifacts repositories delete n8n-repo --location=$REGION
Cloud SQL Instance:
gcloud sql instances delete n8n-db
Secrets:
gcloud secrets delete n8n-db-password
gcloud secrets delete n8n-encryption-key
gcloud secrets delete n8n-redis-auth # Queue Mode only
Service Account:
gcloud iam service-accounts delete n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com
Cloud Run Services:
gcloud run services delete n8n --region=$REGION
gcloud run services delete n8n-worker --region=$REGION # Queue Mode only
Cloud Memorystore Redis (Queue Mode only):
gcloud redis instances delete n8n-redis --region=$REGION
3. Alternative: Use Google Cloud Console - Navigate to each service (Cloud Run, Cloud SQL, Memorystore, Secret Manager, IAM, Artifact Registry) - Identify and delete resources with names matching the Terraform configuration - This visual approach can be easier for identifying partially-created resources
terraform init
terraform plan # Verify no conflicts remain
terraform apply
Pro tip: If you're unsure which resources were created, check the Terraform configuration files to see the exact resource names and types that will be provisioned.
Huge thanks to @alliecatowo for this valuable addition!
For more details and usage instructions, please see the terraform/ directory in this repository.
---
And there you have it - a fully functional n8n instance running on Google Cloud Run. You get all the benefits of self-hosting without the headache of managing servers. Your workflows run reliably, your data stays under your control, and you only pay for what you use.
基础设施即代码方案,降低n8n部署门槛,生态完整但文档依赖,适合有云计算经验的用户。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
总体来看,n8n AI工作流自动化 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | self-host-n8n-on-gcr |
| 原始描述 | 开源n8n工作流:Self-host n8n on Google Cloud without the subscription fees or server headaches 。⭐602 · HCL |
| Topics | n8n工作流自动化谷歌云开源自托管AI代理 |
| GitHub | https://github.com/datawranglerai/self-host-n8n-on-gcr |
| License | MIT |
| 语言 | HCL |
收录时间:2026-05-13 · 更新时间:2026-05-16 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。