{
  "@context": "https://schema.org",
  "@id": "https://aggr.aymericbeaumet.com/items/philschmid-de/2025-10-30-build-your-first-ai-agent-with-gemini-n8n-and-google-cloud/#webpage",
  "@type": [
    "WebPage",
    "ArchiveComponent"
  ],
  "articleBody": "[n8n](https://n8n.io/) is a powerful, open-source workflow automation tool that allows you to connect and automate different services and applications. This guide will walk you through deploying n8n on Google Cloud Run with a PostgreSQL database for persistent storage and creating a simple AI Agent using Google Gemini 2.5.\n\nBefore we start you need a Google Cloud Platform (GCP) account with a billing account configured.\n\n## Step 1: Install and Configure gcloud CLI\n\nTo interact with Google Cloud from your terminal, you need the Google Cloud CLI.\n\n1. **Install the gcloud CLI:** You can install the Google Cloud CLI using the following command, or follow the [official installation instructions](https://cloud.google.com/sdk/docs/install) for your specific operating system.\n\n   Bash\n\n   ```bash\n   curl https://sdk.cloud.google.com | bash\n   exec -l $SHELL\n   gcloud init\n   ```\n\n   Run `gcloud version` to verify the installation.\n\n2. **Login to Google Cloud:** Once installed, authenticate with your Google Cloud account:\n\n   Bash\n\n   ```bash\n   gcloud auth login\n   ```\n\n   A browser window will open asking you to log in and allow the Google Cloud SDK to access your account. Copy the authentication code and paste it into the terminal.\n\n## Step 2: Setup Google Cloud Project\n\nWe need to set up a new Google Cloud project and enable the necessary services.\n\n1. **Create a new project:**\n\n   Bash\n\n   ```bash\n   export PROJECT_ID=\"n8n-gemini-$(head /dev/urandom | tr -dc a-z0-9 | head -c 10)\"\n   gcloud projects create \"$PROJECT_ID\" --name=\"n8n Gemini Quickstart\"\n   gcloud config set project \"$PROJECT_ID\"\n   ```\n\n2. **Link Billing Account:** You need to enable billing for your new project. Run the command below and open the URL in your browser to link your billing account.\n\n   Bash\n\n   ```bash\n   echo \"https://console.cloud.google.com/billing/linkedaccount?project=$PROJECT_ID\"\n   ```\n\n3. **Set environment variables:**\n\n   Bash\n\n   ```bash\n   export REGION=\"us-central1\" # Change to your preferred region, e.g. us-east1, us-west1, etc.\n   ```\n\n4. **Enable necessary APIs:**\n\n   Bash\n\n   ```bash\n   gcloud services enable run.googleapis.com \\\n       sqladmin.googleapis.com \\\n       secretmanager.googleapis.com \\\n       iam.googleapis.com\n   ```\n\n## Step 3: Setup Database and Secrets\n\nn8n requires a database to store its data. We'll use Cloud SQL for PostgreSQL and Secret Manager to securely store credentials. We are using a `db-f1-micro` tier for cost-effectiveness, but you can adjust the parameters like tier, storage size, and region based on your needs. For more configuration options, refer to the [official documentation](https://docs.cloud.google.com/sql/docs/postgres/create-instance).\n\n*Note: This can take ~10-15 minutes.*\n\nBash\n\n```bash\nexport N8N_DB_PASSWORD=$(openssl rand -base64 16)\nexport N8N_ENCRYPTION_KEY=$(openssl rand -base64 42)\n \n# Create Cloud SQL instance\ngcloud sql instances create n8n-db \\\n    --database-version=POSTGRES_13 \\\n    --tier=db-f1-micro \\\n    --region=$REGION \\\n    --root-password=$N8N_DB_PASSWORD \\\n    --storage-size=10GB \\\n    --no-backup \\\n    --storage-type=HDD\n \n# Create database and user\ngcloud sql databases create n8n --instance=n8n-db\ngcloud sql users create n8n-user \\\n    --instance=n8n-db \\\n    --password=$N8N_DB_PASSWORD\n \n# Store secrets in Secret Manager\necho $N8N_DB_PASSWORD | gcloud secrets create n8n-db-password --data-file=- --replication-policy=\"automatic\"\necho $N8N_ENCRYPTION_KEY | gcloud secrets create n8n-encryption-key --data-file=- --replication-policy=\"automatic\"\n```\n\n## Step 4: Deploy n8n to Cloud Run\n\nNow we'll deploy n8n to Cloud Run, connecting it to our database and secrets. We need to create a service account for n8n and grant it access to the secrets, then deploy the n8n container to Cloud Run with the necessary environment variables and secrets.\n\n1. **Create a service account for n8n:**\n\n   Bash\n\n   ```bash\n   gcloud iam service-accounts create n8n-service-account \\\n       --display-name=\"n8n Service Account\"\n   export SERVICE_ACCOUNT_EMAIL=\"n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com\"\n   ```\n\n2. **Grant necessary permissions:**\n\n   Bash\n\n   ```bash\n   gcloud secrets add-iam-policy-binding n8n-db-password \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/secretmanager.secretAccessor\"\n   gcloud secrets add-iam-policy-binding n8n-encryption-key \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/secretmanager.secretAccessor\"\n   gcloud projects add-iam-policy-binding $PROJECT_ID \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/cloudsql.client\"\n   ```\n\n3. **Deploy to Cloud Run:**\n\n   Bash\n\n   ```bash\n   DB_CONNECTION_NAME=\"$PROJECT_ID:$REGION:n8n-db\"\n\n   gcloud run deploy n8n \\\n       --image=n8nio/n8n:latest \\\n       --region=$REGION \\\n       --allow-unauthenticated \\\n       --port=5678 \\\n       --memory=2Gi \\\n       --cpu=1 \\\n       --no-cpu-throttling \\\n       --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/$DB_CONNECTION_NAME,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true\" \\\n       --set-secrets=\"DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest\" \\\n       --add-cloudsql-instances=$DB_CONNECTION_NAME \\\n       --service-account=$SERVICE_ACCOUNT_EMAIL\n   ```\n\n   *Note: We use `--no-cpu-throttling` to ensure n8n's background processes (like schedules and wait nodes) continue running even when not actively handling an HTTP request.*\n\nAfter a successful deployment, Cloud Run will output the URL of your n8n instance. This should look like:\n\n```plaintext\nDone.\nService [n8n] revision [n8n-00001-qqn] has been deployed and is serving 100 percent of traffic.\nService URL: https://n8n-780597096402.us-central1.run.app\n```\n\n## Step 5: Create your first Gemini Agent\n\nAfter you access your n8n instance for the first time, you will be prompted to set up an owner account. Follow the instructions to create an owner account. Here you can also add your enterprise license if you have one. Awesome, once done you should see a screen like this:\n\n![n8n](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/n8n.png)\n\nWe are going to create an Agent from scratch. But before we create the Agent we need to add our Gemini API Key. Click on \"Credentials\" and then \"Add first credential\" and search for \"Google Gemini (PaLM) API\". Click on \"Create\" and follow the instructions to create a new credential. If you don't have a Gemini API Key, you can get one from the [AI Studio](https://aistudio.google.com/app/api-keys).\n\n![api-key](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/api-key.png)\n\nOnce validated go back to \"Workflows\" and click on \"Start from scratch\". You should now land in the \"editor\". Click \"Add first step\" and search for \"AI Agent\". Now, you should be in the in configuration of the AI Agent. At the bottom in the middle of the screen you should see \"Chat Model\", \"Memory\" and \"Tool\". Click on \"Chat Model\"\n\n![agent-editor](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-editor.png)\n\nThen search for \"Google Gemini Chat Model\". There you should be able to select your credentials and the model you want to use. Once defined click \"Back to canvas\" (top left corner). You should now see a \"Basic AI Agent\" with Gemini.\n\n![agent](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent.png)\n\nLets try it! Click on \"Open Chat\" and ask it a question.\n\n![agent-chat](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-chat.png)\n\nAwesome, it works! Now, lets add some tools and make it an Agent. Therefore click on \"+\" at \"tool\" under the AI Agent. Now, you should see a list of tools you can add to your Agent, including MCP servers, vector databases, or hundreds of other tools.\n\nLet's try to add the \"MCP (Model Context Protocol) Client\". MCP is a standard that allows LLMs to connect to external data sources without custom integration code. We will use it to connect Gemini to a dummy weather service. As endpoint add `https://gemini-api-demos.uc.r.appspot.com/mcp` (Note: There is no guarantee that this endpoint is always available.) Once you have added your MCP server click on \"back to canvas\".\n\nYour Agent should now have a tool connection to a \"MCP Client\".\n\n![agent-mcp](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp.png)\n\nOkay, lets test it. Click on \"Open Chat\" and ask it about the weather in New York, you have to include the \"date\" in your question, e.g. `What is the weather in New York on 2025-10-29?`\n\n![agent-mcp-chat](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp-chat.png)\n\nAwesome, it works! During the execution should have seen the Agent first calling Gemini, which outputs a structured call, to call the MCP Server, the MCP Server response was then sent back to Gemini, which generates the final response.\n\nDon't forget to delete your Google Cloud resources when you are done. You can delete the resources using the following command:\n\nBash\n\n```bash\ngcloud run services delete n8n --region=$REGION \ngcloud sql instances delete n8n-db \ngcloud secrets delete n8n-db-password \ngcloud secrets delete n8n-encryption-key \ngcloud iam service-accounts delete $SERVICE_ACCOUNT_EMAIL \ngcloud projects delete $PROJECT_ID \n```\n\n## Next Steps\n\nCongratz! You have successfully deployed n8n to Google Cloud Run and created your first AI Agent using Gemini 2.5. Now it's time to explore more advanced features, add more tools and build complex workflows to automate your processes. As you move from a proof-of-concept to production, consider these resources:\n\n- **Community Workflows**: [Over 600 community build Gemini n8n workflows](https://n8n.io/workflows/?integrations=Google+Gemini+Chat+Model)\n- **Scaling n8n**: For high-load setups, look into [n8n's Queue Mode](https://docs.n8n.io/hosting/scaling/), which separates the main process from execution workers.\n- **Infrastructure Optimization**: Optimize [concurrency](https://cloud.google.com/run/docs/about-concurrency), [startup CPU boost](https://cloud.google.com/run/docs/configuring/services/cpu#startup-boost), [database](https://docs.n8n.io/hosting/execution-data/#pruning-execution-data)\n- **Advanced AI Nodes**: Explore n8n's [advanced AI documentation](https://docs.n8n.io/advanced-ai/) to learn about different types of memory, output parsers, and custom tools.\n- **Human-in-the-loop**: specific nodes can be used to ask for [human approval](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait/) before executing sensitive actions.\n- [**n8n Community Forum**](https://community.n8n.io): The best place to ask questions, share your workflows, and learn from others.\n- [**n8n YouTube Channel**](https://www.youtube.com/@n8n-io)\\*\\*: Great for visual tutorials and deep dives into complex use cases.\n",
  "authors": [],
  "captured_at": "2026-09-27T19:29:15.293681927+00:00",
  "category": "programming",
  "content_html": "<p><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://n8n.io/\">n8n</a> is a powerful, open-source workflow automation tool that allows you to connect and automate different services and applications. This guide will walk you through deploying n8n on Google Cloud Run with a PostgreSQL database for persistent storage and creating a simple AI Agent using Google Gemini 2.5.</p>\n<p>Before we start you need a Google Cloud Platform (GCP) account with a billing account configured.</p>\n<h2>Step 1: Install and Configure gcloud CLI</h2>\n<p>To interact with Google Cloud from your terminal, you need the Google Cloud CLI.</p>\n<ol>\n<li>\n<p><strong>Install the gcloud CLI:</strong> You can install the Google Cloud CLI using the following command, or follow the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://cloud.google.com/sdk/docs/install\">official installation instructions</a> for your specific operating system.</p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">curl</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> https://sdk.cloud.google.com</span> <span class=\"syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell\">|</span> <span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">bash</span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-support syntax-function syntax-exec syntax-shell\">exec</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> -l <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SHELL</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> init</span>\n</span></span></code></pre>\n<p>Run <code>gcloud version</code> to verify the installation.</p>\n</li>\n<li>\n<p><strong>Login to Google Cloud:</strong> Once installed, authenticate with your Google Cloud account:</p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> auth login</span>\n</span></span></code></pre>\n<p>A browser window will open asking you to log in and allow the Google Cloud SDK to access your account. Copy the authentication code and paste it into the terminal.</p>\n</li>\n</ol>\n<h2>Step 2: Setup Google Cloud Project</h2>\n<p>We need to set up a new Google Cloud project and enable the necessary services.</p>\n<ol>\n<li>\n<p><strong>Create a new project:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-storage syntax-modifier syntax-shell\">export</span> <span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">PROJECT_ID</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>n8n-gemini-<span class=\"syntax-meta syntax-group syntax-expansion syntax-command syntax-parens syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-begin syntax-shell\">(</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">head</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> /dev/urandom</span> <span class=\"syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell\">|</span> <span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">tr</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> -</span>dc</span> a-z0-9</span> <span class=\"syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell\">|</span> <span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">head</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> -</span>c</span> 10</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-end syntax-shell\">)</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> projects create <span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>name</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>n8n Gemini Quickstart<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> config set project <span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n</span></span></code></pre>\n</li>\n<li>\n<p><strong>Link Billing Account:</strong> You need to enable billing for your new project. Run the command below and open the URL in your browser to link your billing account.</p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-support syntax-function syntax-echo syntax-shell\">echo</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> <span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>https://console.cloud.google.com/billing/linkedaccount?project=<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n</span></span></code></pre>\n</li>\n<li>\n<p><strong>Set environment variables:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-storage syntax-modifier syntax-shell\">export</span> <span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">REGION</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>us-central1<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span></span> <span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-comment syntax-begin syntax-shell\">#</span></span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"> Change to your preferred region, e.g. us-east1, us-west1, etc.</span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\">\n</span></span></span></code></pre>\n</li>\n<li>\n<p><strong>Enable necessary APIs:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> services enable run.googleapis.com <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span>    sqladmin.googleapis.com <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span>    secretmanager.googleapis.com <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span>    iam.googleapis.com</span>\n</span></span></code></pre>\n</li>\n</ol>\n<h2>Step 3: Setup Database and Secrets</h2>\n<p>n8n requires a database to store its data. We'll use Cloud SQL for PostgreSQL and Secret Manager to securely store credentials. We are using a <code>db-f1-micro</code> tier for cost-effectiveness, but you can adjust the parameters like tier, storage size, and region based on your needs. For more configuration options, refer to the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://docs.cloud.google.com/sql/docs/postgres/create-instance\">official documentation</a>.</p>\n<p><em>Note: This can take ~10-15 minutes.</em></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-storage syntax-modifier syntax-shell\">export</span> <span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">N8N_DB_PASSWORD</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-meta syntax-group syntax-expansion syntax-command syntax-parens syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-begin syntax-shell\">(</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">openssl</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> rand<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> -</span>base64</span> 16</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-end syntax-shell\">)</span></span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-storage syntax-modifier syntax-shell\">export</span> <span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">N8N_ENCRYPTION_KEY</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-meta syntax-group syntax-expansion syntax-command syntax-parens syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-begin syntax-shell\">(</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">openssl</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> rand<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> -</span>base64</span> 42</span><span class=\"syntax-punctuation syntax-section syntax-parens syntax-end syntax-shell\">)</span></span></span></span>\n \n<span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-comment syntax-begin syntax-shell\">#</span></span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"> Create Cloud SQL instance</span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\">\n</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> sql instances create n8n-db <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>database-version</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>POSTGRES_13 <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>tier</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>db-f1-micro <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>region</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">REGION</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>root-password</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">N8N_DB_PASSWORD</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>storage-size</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>10GB <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>no-backup</span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>storage-type</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>HDD</span>\n \n<span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-comment syntax-begin syntax-shell\">#</span></span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"> Create database and user</span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\">\n</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> sql databases create n8n<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>instance</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>n8n-db</span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> sql users create n8n-user <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>instance</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>n8n-db <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>password</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">N8N_DB_PASSWORD</span></span></span>\n \n<span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-comment syntax-begin syntax-shell\">#</span></span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\"> Store secrets in Secret Manager</span><span class=\"syntax-comment syntax-line syntax-number-sign syntax-shell\">\n</span><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-support syntax-function syntax-echo syntax-shell\">echo</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">N8N_DB_PASSWORD</span></span></span> <span class=\"syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell\">|</span> <span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets create n8n-db-password<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>data-file</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>-<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>replication-policy</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>automatic<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-support syntax-function syntax-echo syntax-shell\">echo</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">N8N_ENCRYPTION_KEY</span></span></span> <span class=\"syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell\">|</span> <span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets create n8n-encryption-key<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>data-file</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>-<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>replication-policy</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>automatic<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n</span></span></code></pre>\n<h2>Step 4: Deploy n8n to Cloud Run</h2>\n<p>Now we'll deploy n8n to Cloud Run, connecting it to our database and secrets. We need to create a service account for n8n and grant it access to the secrets, then deploy the n8n container to Cloud Run with the necessary environment variables and secrets.</p>\n<ol>\n<li>\n<p><strong>Create a service account for n8n:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> iam service-accounts create n8n-service-account <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>display-name</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>n8n Service Account<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-storage syntax-modifier syntax-shell\">export</span> <span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">SERVICE_ACCOUNT_EMAIL</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>n8n-service-account@<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span>.iam.gserviceaccount.com<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span></span>\n</span></span></code></pre>\n</li>\n<li>\n<p><strong>Grant necessary permissions:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets add-iam-policy-binding n8n-db-password <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>member</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>serviceAccount:<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SERVICE_ACCOUNT_EMAIL</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>role</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>roles/secretmanager.secretAccessor<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets add-iam-policy-binding n8n-encryption-key <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>member</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>serviceAccount:<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SERVICE_ACCOUNT_EMAIL</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>role</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>roles/secretmanager.secretAccessor<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> projects add-iam-policy-binding <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>member</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>serviceAccount:<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SERVICE_ACCOUNT_EMAIL</span></span><span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>role</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>roles/cloudsql.client<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n</span></span></code></pre>\n</li>\n<li>\n<p><strong>Deploy to Cloud Run:</strong></p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-variable syntax-other syntax-readwrite syntax-assignment syntax-shell\">DB_CONNECTION_NAME</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-shell\">=</span><span class=\"syntax-string syntax-unquoted syntax-shell\"><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span>:<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">REGION</span></span>:n8n-db<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span></span>\n\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> run deploy n8n <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>image</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>n8nio/n8n:latest <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>region</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">REGION</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>allow-unauthenticated</span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>port</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>5678 <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>memory</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>2Gi <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>cpu</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span>1 <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>no-cpu-throttling</span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>set-env-vars</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>N8N_PORT=5678,N8N_PROTOCOL=https,DB_TYPE=postgresdb,DB_POSTGRESDB_DATABASE=n8n,DB_POSTGRESDB_USER=n8n-user,DB_POSTGRESDB_HOST=/cloudsql/<span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">DB_CONNECTION_NAME</span></span>,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>set-secrets</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-string syntax-quoted syntax-double syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell\">&quot;</span>DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest<span class=\"syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell\">&quot;</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>add-cloudsql-instances</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">DB_CONNECTION_NAME</span></span> <span class=\"syntax-punctuation syntax-separator syntax-continuation syntax-line syntax-shell\">\\\n</span><span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\">    --</span>service-account</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SERVICE_ACCOUNT_EMAIL</span></span></span>\n</span></span></code></pre>\n<p><em>Note: We use <code>--no-cpu-throttling</code> to ensure n8n's background processes (like schedules and wait nodes) continue running even when not actively handling an HTTP request.</em></p>\n</li>\n</ol>\n<p>After a successful deployment, Cloud Run will output the URL of your n8n instance. This should look like:</p>\n<pre><code class=\"language-plaintext\"><span class=\"code-snippet\">Done.\nService [n8n] revision [n8n-00001-qqn] has been deployed and is serving 100 percent of traffic.\nService URL: https://n8n-780597096402.us-central1.run.app\n</span></code></pre>\n<h2>Step 5: Create your first Gemini Agent</h2>\n<p>After you access your n8n instance for the first time, you will be prompted to set up an owner account. Follow the instructions to create an owner account. Here you can also add your enterprise license if you have one. Awesome, once done you should see a screen like this:</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/n8n.png\" alt=\"n8n\" loading=\"eager\" decoding=\"async\" fetchpriority=\"high\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>We are going to create an Agent from scratch. But before we create the Agent we need to add our Gemini API Key. Click on &quot;Credentials&quot; and then &quot;Add first credential&quot; and search for &quot;Google Gemini (PaLM) API&quot;. Click on &quot;Create&quot; and follow the instructions to create a new credential. If you don't have a Gemini API Key, you can get one from the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://aistudio.google.com/app/api-keys\">AI Studio</a>.</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/api-key.png\" alt=\"api-key\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Once validated go back to &quot;Workflows&quot; and click on &quot;Start from scratch&quot;. You should now land in the &quot;editor&quot;. Click &quot;Add first step&quot; and search for &quot;AI Agent&quot;. Now, you should be in the in configuration of the AI Agent. At the bottom in the middle of the screen you should see &quot;Chat Model&quot;, &quot;Memory&quot; and &quot;Tool&quot;. Click on &quot;Chat Model&quot;</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-editor.png\" alt=\"agent-editor\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Then search for &quot;Google Gemini Chat Model&quot;. There you should be able to select your credentials and the model you want to use. Once defined click &quot;Back to canvas&quot; (top left corner). You should now see a &quot;Basic AI Agent&quot; with Gemini.</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent.png\" alt=\"agent\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Lets try it! Click on &quot;Open Chat&quot; and ask it a question.</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-chat.png\" alt=\"agent-chat\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Awesome, it works! Now, lets add some tools and make it an Agent. Therefore click on &quot;+&quot; at &quot;tool&quot; under the AI Agent. Now, you should see a list of tools you can add to your Agent, including MCP servers, vector databases, or hundreds of other tools.</p>\n<p>Let's try to add the &quot;MCP (Model Context Protocol) Client&quot;. MCP is a standard that allows LLMs to connect to external data sources without custom integration code. We will use it to connect Gemini to a dummy weather service. As endpoint add <code>https://gemini-api-demos.uc.r.appspot.com/mcp</code> (Note: There is no guarantee that this endpoint is always available.) Once you have added your MCP server click on &quot;back to canvas&quot;.</p>\n<p>Your Agent should now have a tool connection to a &quot;MCP Client&quot;.</p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp.png\" alt=\"agent-mcp\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Okay, lets test it. Click on &quot;Open Chat&quot; and ask it about the weather in New York, you have to include the &quot;date&quot; in your question, e.g. <code>What is the weather in New York on 2025-10-29?</code></p>\n<p><picture class=\"article-picture article-picture-fallback\" style=\"--image-ratio:16 / 9\"><img src=\"https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp-chat.png\" alt=\"agent-mcp-chat\" loading=\"lazy\" decoding=\"async\" fetchpriority=\"low\" referrerpolicy=\"no-referrer\" class=\"progressive-image\"></picture></p>\n<p>Awesome, it works! During the execution should have seen the Agent first calling Gemini, which outputs a structured call, to call the MCP Server, the MCP Server response was then sent back to Gemini, which generates the final response.</p>\n<p>Don't forget to delete your Google Cloud resources when you are done. You can delete the resources using the following command:</p>\n<p>Bash</p>\n<pre><code class=\"language-bash\"><span class=\"code-snippet\" data-language=\"Shell\"><span class=\"syntax-source syntax-shell syntax-bash\"><span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> run services delete n8n<span class=\"syntax-variable syntax-parameter syntax-option syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-parameter syntax-shell\"> --</span>region</span><span class=\"syntax-keyword syntax-operator syntax-assignment syntax-option syntax-shell\">=</span><span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">REGION</span></span> </span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> sql instances delete n8n-db </span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets delete n8n-db-password </span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> secrets delete n8n-encryption-key </span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> iam service-accounts delete <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">SERVICE_ACCOUNT_EMAIL</span></span> </span>\n<span class=\"syntax-meta syntax-function-call syntax-shell\"><span class=\"syntax-variable syntax-function syntax-shell\">gcloud</span></span><span class=\"syntax-meta syntax-function-call syntax-arguments syntax-shell\"> projects delete <span class=\"syntax-meta syntax-group syntax-expansion syntax-parameter syntax-shell\"><span class=\"syntax-punctuation syntax-definition syntax-variable syntax-shell\">$</span><span class=\"syntax-variable syntax-other syntax-readwrite syntax-shell\">PROJECT_ID</span></span> </span>\n</span></span></code></pre>\n<h2>Next Steps</h2>\n<p>Congratz! You have successfully deployed n8n to Google Cloud Run and created your first AI Agent using Gemini 2.5. Now it's time to explore more advanced features, add more tools and build complex workflows to automate your processes. As you move from a proof-of-concept to production, consider these resources:</p>\n<ul>\n<li><strong>Community Workflows</strong>: <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://n8n.io/workflows/?integrations=Google+Gemini+Chat+Model\">Over 600 community build Gemini n8n workflows</a></li>\n<li><strong>Scaling n8n</strong>: For high-load setups, look into <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://docs.n8n.io/hosting/scaling/\">n8n's Queue Mode</a>, which separates the main process from execution workers.</li>\n<li><strong>Infrastructure Optimization</strong>: Optimize <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://cloud.google.com/run/docs/about-concurrency\">concurrency</a>, <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://cloud.google.com/run/docs/configuring/services/cpu#startup-boost\">startup CPU boost</a>, <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://docs.n8n.io/hosting/execution-data/#pruning-execution-data\">database</a></li>\n<li><strong>Advanced AI Nodes</strong>: Explore n8n's <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://docs.n8n.io/advanced-ai/\">advanced AI documentation</a> to learn about different types of memory, output parsers, and custom tools.</li>\n<li><strong>Human-in-the-loop</strong>: specific nodes can be used to ask for <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait/\">human approval</a> before executing sensitive actions.</li>\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://community.n8n.io\"><strong>n8n Community Forum</strong></a>: The best place to ask questions, share your workflows, and learn from others.</li>\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://www.youtube.com/@n8n-io\"><strong>n8n YouTube Channel</strong></a>**: Great for visual tutorials and deep dives into complex use cases.</li>\n</ul>\n",
  "content_markdown": "[n8n](https://n8n.io/) is a powerful, open-source workflow automation tool that allows you to connect and automate different services and applications. This guide will walk you through deploying n8n on Google Cloud Run with a PostgreSQL database for persistent storage and creating a simple AI Agent using Google Gemini 2.5.\n\nBefore we start you need a Google Cloud Platform (GCP) account with a billing account configured.\n\n## Step 1: Install and Configure gcloud CLI\n\nTo interact with Google Cloud from your terminal, you need the Google Cloud CLI.\n\n1. **Install the gcloud CLI:** You can install the Google Cloud CLI using the following command, or follow the [official installation instructions](https://cloud.google.com/sdk/docs/install) for your specific operating system.\n\n   Bash\n\n   ```bash\n   curl https://sdk.cloud.google.com | bash\n   exec -l $SHELL\n   gcloud init\n   ```\n\n   Run `gcloud version` to verify the installation.\n\n2. **Login to Google Cloud:** Once installed, authenticate with your Google Cloud account:\n\n   Bash\n\n   ```bash\n   gcloud auth login\n   ```\n\n   A browser window will open asking you to log in and allow the Google Cloud SDK to access your account. Copy the authentication code and paste it into the terminal.\n\n## Step 2: Setup Google Cloud Project\n\nWe need to set up a new Google Cloud project and enable the necessary services.\n\n1. **Create a new project:**\n\n   Bash\n\n   ```bash\n   export PROJECT_ID=\"n8n-gemini-$(head /dev/urandom | tr -dc a-z0-9 | head -c 10)\"\n   gcloud projects create \"$PROJECT_ID\" --name=\"n8n Gemini Quickstart\"\n   gcloud config set project \"$PROJECT_ID\"\n   ```\n\n2. **Link Billing Account:** You need to enable billing for your new project. Run the command below and open the URL in your browser to link your billing account.\n\n   Bash\n\n   ```bash\n   echo \"https://console.cloud.google.com/billing/linkedaccount?project=$PROJECT_ID\"\n   ```\n\n3. **Set environment variables:**\n\n   Bash\n\n   ```bash\n   export REGION=\"us-central1\" # Change to your preferred region, e.g. us-east1, us-west1, etc.\n   ```\n\n4. **Enable necessary APIs:**\n\n   Bash\n\n   ```bash\n   gcloud services enable run.googleapis.com \\\n       sqladmin.googleapis.com \\\n       secretmanager.googleapis.com \\\n       iam.googleapis.com\n   ```\n\n## Step 3: Setup Database and Secrets\n\nn8n requires a database to store its data. We'll use Cloud SQL for PostgreSQL and Secret Manager to securely store credentials. We are using a `db-f1-micro` tier for cost-effectiveness, but you can adjust the parameters like tier, storage size, and region based on your needs. For more configuration options, refer to the [official documentation](https://docs.cloud.google.com/sql/docs/postgres/create-instance).\n\n*Note: This can take ~10-15 minutes.*\n\nBash\n\n```bash\nexport N8N_DB_PASSWORD=$(openssl rand -base64 16)\nexport N8N_ENCRYPTION_KEY=$(openssl rand -base64 42)\n \n# Create Cloud SQL instance\ngcloud sql instances create n8n-db \\\n    --database-version=POSTGRES_13 \\\n    --tier=db-f1-micro \\\n    --region=$REGION \\\n    --root-password=$N8N_DB_PASSWORD \\\n    --storage-size=10GB \\\n    --no-backup \\\n    --storage-type=HDD\n \n# Create database and user\ngcloud sql databases create n8n --instance=n8n-db\ngcloud sql users create n8n-user \\\n    --instance=n8n-db \\\n    --password=$N8N_DB_PASSWORD\n \n# Store secrets in Secret Manager\necho $N8N_DB_PASSWORD | gcloud secrets create n8n-db-password --data-file=- --replication-policy=\"automatic\"\necho $N8N_ENCRYPTION_KEY | gcloud secrets create n8n-encryption-key --data-file=- --replication-policy=\"automatic\"\n```\n\n## Step 4: Deploy n8n to Cloud Run\n\nNow we'll deploy n8n to Cloud Run, connecting it to our database and secrets. We need to create a service account for n8n and grant it access to the secrets, then deploy the n8n container to Cloud Run with the necessary environment variables and secrets.\n\n1. **Create a service account for n8n:**\n\n   Bash\n\n   ```bash\n   gcloud iam service-accounts create n8n-service-account \\\n       --display-name=\"n8n Service Account\"\n   export SERVICE_ACCOUNT_EMAIL=\"n8n-service-account@$PROJECT_ID.iam.gserviceaccount.com\"\n   ```\n\n2. **Grant necessary permissions:**\n\n   Bash\n\n   ```bash\n   gcloud secrets add-iam-policy-binding n8n-db-password \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/secretmanager.secretAccessor\"\n   gcloud secrets add-iam-policy-binding n8n-encryption-key \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/secretmanager.secretAccessor\"\n   gcloud projects add-iam-policy-binding $PROJECT_ID \\\n       --member=\"serviceAccount:$SERVICE_ACCOUNT_EMAIL\" \\\n       --role=\"roles/cloudsql.client\"\n   ```\n\n3. **Deploy to Cloud Run:**\n\n   Bash\n\n   ```bash\n   DB_CONNECTION_NAME=\"$PROJECT_ID:$REGION:n8n-db\"\n\n   gcloud run deploy n8n \\\n       --image=n8nio/n8n:latest \\\n       --region=$REGION \\\n       --allow-unauthenticated \\\n       --port=5678 \\\n       --memory=2Gi \\\n       --cpu=1 \\\n       --no-cpu-throttling \\\n       --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/$DB_CONNECTION_NAME,DB_POSTGRESDB_PORT=5432,DB_POSTGRESDB_SCHEMA=public,GENERIC_TIMEZONE=UTC,QUEUE_HEALTH_CHECK_ACTIVE=true\" \\\n       --set-secrets=\"DB_POSTGRESDB_PASSWORD=n8n-db-password:latest,N8N_ENCRYPTION_KEY=n8n-encryption-key:latest\" \\\n       --add-cloudsql-instances=$DB_CONNECTION_NAME \\\n       --service-account=$SERVICE_ACCOUNT_EMAIL\n   ```\n\n   *Note: We use `--no-cpu-throttling` to ensure n8n's background processes (like schedules and wait nodes) continue running even when not actively handling an HTTP request.*\n\nAfter a successful deployment, Cloud Run will output the URL of your n8n instance. This should look like:\n\n```plaintext\nDone.\nService [n8n] revision [n8n-00001-qqn] has been deployed and is serving 100 percent of traffic.\nService URL: https://n8n-780597096402.us-central1.run.app\n```\n\n## Step 5: Create your first Gemini Agent\n\nAfter you access your n8n instance for the first time, you will be prompted to set up an owner account. Follow the instructions to create an owner account. Here you can also add your enterprise license if you have one. Awesome, once done you should see a screen like this:\n\n![n8n](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/n8n.png)\n\nWe are going to create an Agent from scratch. But before we create the Agent we need to add our Gemini API Key. Click on \"Credentials\" and then \"Add first credential\" and search for \"Google Gemini (PaLM) API\". Click on \"Create\" and follow the instructions to create a new credential. If you don't have a Gemini API Key, you can get one from the [AI Studio](https://aistudio.google.com/app/api-keys).\n\n![api-key](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/api-key.png)\n\nOnce validated go back to \"Workflows\" and click on \"Start from scratch\". You should now land in the \"editor\". Click \"Add first step\" and search for \"AI Agent\". Now, you should be in the in configuration of the AI Agent. At the bottom in the middle of the screen you should see \"Chat Model\", \"Memory\" and \"Tool\". Click on \"Chat Model\"\n\n![agent-editor](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-editor.png)\n\nThen search for \"Google Gemini Chat Model\". There you should be able to select your credentials and the model you want to use. Once defined click \"Back to canvas\" (top left corner). You should now see a \"Basic AI Agent\" with Gemini.\n\n![agent](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent.png)\n\nLets try it! Click on \"Open Chat\" and ask it a question.\n\n![agent-chat](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-chat.png)\n\nAwesome, it works! Now, lets add some tools and make it an Agent. Therefore click on \"+\" at \"tool\" under the AI Agent. Now, you should see a list of tools you can add to your Agent, including MCP servers, vector databases, or hundreds of other tools.\n\nLet's try to add the \"MCP (Model Context Protocol) Client\". MCP is a standard that allows LLMs to connect to external data sources without custom integration code. We will use it to connect Gemini to a dummy weather service. As endpoint add `https://gemini-api-demos.uc.r.appspot.com/mcp` (Note: There is no guarantee that this endpoint is always available.) Once you have added your MCP server click on \"back to canvas\".\n\nYour Agent should now have a tool connection to a \"MCP Client\".\n\n![agent-mcp](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp.png)\n\nOkay, lets test it. Click on \"Open Chat\" and ask it about the weather in New York, you have to include the \"date\" in your question, e.g. `What is the weather in New York on 2025-10-29?`\n\n![agent-mcp-chat](https://www.philschmid.de/static/blog/n8n-cloud-run-gemini/agent-mcp-chat.png)\n\nAwesome, it works! During the execution should have seen the Agent first calling Gemini, which outputs a structured call, to call the MCP Server, the MCP Server response was then sent back to Gemini, which generates the final response.\n\nDon't forget to delete your Google Cloud resources when you are done. You can delete the resources using the following command:\n\nBash\n\n```bash\ngcloud run services delete n8n --region=$REGION \ngcloud sql instances delete n8n-db \ngcloud secrets delete n8n-db-password \ngcloud secrets delete n8n-encryption-key \ngcloud iam service-accounts delete $SERVICE_ACCOUNT_EMAIL \ngcloud projects delete $PROJECT_ID \n```\n\n## Next Steps\n\nCongratz! You have successfully deployed n8n to Google Cloud Run and created your first AI Agent using Gemini 2.5. Now it's time to explore more advanced features, add more tools and build complex workflows to automate your processes. As you move from a proof-of-concept to production, consider these resources:\n\n- **Community Workflows**: [Over 600 community build Gemini n8n workflows](https://n8n.io/workflows/?integrations=Google+Gemini+Chat+Model)\n- **Scaling n8n**: For high-load setups, look into [n8n's Queue Mode](https://docs.n8n.io/hosting/scaling/), which separates the main process from execution workers.\n- **Infrastructure Optimization**: Optimize [concurrency](https://cloud.google.com/run/docs/about-concurrency), [startup CPU boost](https://cloud.google.com/run/docs/configuring/services/cpu#startup-boost), [database](https://docs.n8n.io/hosting/execution-data/#pruning-execution-data)\n- **Advanced AI Nodes**: Explore n8n's [advanced AI documentation](https://docs.n8n.io/advanced-ai/) to learn about different types of memory, output parsers, and custom tools.\n- **Human-in-the-loop**: specific nodes can be used to ask for [human approval](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.wait/) before executing sensitive actions.\n- [**n8n Community Forum**](https://community.n8n.io): The best place to ask questions, share your workflows, and learn from others.\n- [**n8n YouTube Channel**](https://www.youtube.com/@n8n-io)\\*\\*: Great for visual tutorials and deep dives into complex use cases.\n",
  "dateCreated": "2026-09-27T19:29:15.293681927+00:00",
  "date_created": "2025-10-30T00:00:00+00:00",
  "date_modified": "2025-10-30T00:00:00+00:00",
  "date_published": "2025-10-30T00:00:00+00:00",
  "description": "Learn how to deploy n8n on Google Cloud Run with PostgreSQL and create an AI Agent using Google Gemini 2.5.",
  "external_url": "https://www.philschmid.de/n8n-cloud-run-gemini",
  "git": {
    "commit": "ebb0941c5c06a2ab2377342d607535262a3e969e",
    "path": "items/philschmid-de/2025/10/2025-10-30-build-your-first-ai-agent-with-gemini-n8n-and-google-cloud.md",
    "permalink": "https://github.com/aymericbeaumet/aggr-instance/blob/ebb0941c5c06a2ab2377342d607535262a3e969e/items/philschmid-de/2025/10/2025-10-30-build-your-first-ai-agent-with-gemini-n8n-and-google-cloud.md"
  },
  "id": "urn:aggr:item:75ba67b230b9f07623a1aae7834b5734de9d189b",
  "isBasedOn": {
    "@id": "https://www.philschmid.de/n8n-cloud-run-gemini"
  },
  "mainEntity": {
    "@id": "https://www.philschmid.de/n8n-cloud-run-gemini",
    "@type": "CreativeWork",
    "archivedAt": {
      "@id": "https://aggr.aymericbeaumet.com/items/philschmid-de/2025-10-30-build-your-first-ai-agent-with-gemini-n8n-and-google-cloud/#webpage"
    },
    "dateModified": "2025-10-30T00:00:00+00:00",
    "datePublished": "2025-10-30T00:00:00+00:00",
    "headline": "Build your first AI Agent with Gemini, n8n and Google Cloud Run",
    "timeRequired": "PT7M",
    "url": "https://www.philschmid.de/n8n-cloud-run-gemini",
    "wordCount": 1384
  },
  "name": "Archived snapshot: Build your first AI Agent with Gemini, n8n and Google Cloud Run",
  "preview": null,
  "reading_minutes": 7,
  "replicated_at": null,
  "source": "philschmid-de",
  "source_name": "philschmid.de - RSS feed",
  "summary": "Learn how to deploy n8n on Google Cloud Run with PostgreSQL and create an AI Agent using Google Gemini 2.5.",
  "tags": [],
  "temporalCoverage": "2026-09-27T19:29:15.293681927+00:00",
  "title": "Build your first AI Agent with Gemini, n8n and Google Cloud Run",
  "url": "https://aggr.aymericbeaumet.com/items/philschmid-de/2025-10-30-build-your-first-ai-agent-with-gemini-n8n-and-google-cloud/",
  "word_count": 1384
}