Skip to content

Create google-cloudrun-source.yml#1

Merged
Tsukimarf merged 1 commit into
mainfrom
Tsukimarf-patch-1
Nov 28, 2025
Merged

Create google-cloudrun-source.yml#1
Tsukimarf merged 1 commit into
mainfrom
Tsukimarf-patch-1

Conversation

@Tsukimarf

Copy link
Copy Markdown
Owner

Google Cloud Run Service Configuration

‘ This file defines the configuration for deploying a containerized application to Cloud Run

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: my-cloudrun-service
labels:
cloud.googleapis.com/location: asia-southeast1
annotations:
run.googleapis.com/ingress: all
run.googleapis.com/launch-stage: BETA

spec:
template:
metadata:
annotations:
# Autoscaling configuration
autoscaling.knative.dev/minScale: '0'
>autoscaling.knative.dev/maxScale: '10'

    # CPU allocation (always allocated or only during request processing)
    run.googleapis.com/cpu-throttling: 'true'
    
    # Startup probe configuration
    run.googleapis.com/startup-cpu-boost: 'true'
    
    # Execution environment (first gen or second gen)
    run.googleapis.com/execution-environment: gen2
    
    # VPC connector for private network access
    # run.googleapis.com/vpc-access-connector: projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME
    # run.googleapis.com/vpc-access-egress: private-ranges-only
    
spec:
  # Service account for the Cloud Run service
  serviceAccountName: cloudrun-service-account@PROJECT_ID.iam.gserviceaccount.com
  
  # Request timeout (max 3600s for 1st gen, 3600s for 2nd gen)
  timeoutSeconds: 300
  
  # Container configuration
  containers:
  - name: main-container
    # Container image from Google Container Registry or Artifact Registry
    image: gcr.io/PROJECT_ID/IMAGE_NAME:TAG
    
    # Container port
    ports:
    - name: http1
      containerPort: 8080
    
    # Resource limits and requests
    resources:
      limits:
        cpu: '1000m'      # 1 vCPU
        memory: '512Mi'   # 512 MB RAM
      requests:
        cpu: '1000m'
        memory: '512Mi'
    
    # Environment variables
    env:
    - name: NODE_ENV
      value: production
    - name: PORT
      value: '8080'
    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: database-url
          key: latest
    
    # Startup probe (checks if container has started)
    startupProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 0
      periodSeconds: 10
      timeoutSeconds: 1
      failureThreshold: 3
    
    # Liveness probe (checks if container is alive)
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 0
      periodSeconds: 10
      timeoutSeconds: 1
      failureThreshold: 3
    
    # Volume mounts (for Cloud SQL, secrets, etc.)
    # volumeMounts:
    # - name: cloudsql
    #   mountPath: /cloudsql
  
  # Volumes (for Cloud SQL proxy sidecar)
  # volumes:
  # - name: cloudsql
  #   emptyDir: {}
  
  # Cloud SQL proxy sidecar container (if using Cloud SQL)
  # - name: cloud-sql-proxy
  #   image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:latest
  #   args:
  #   - "--structured-logs"
  #   - "--port=5432"
  #   - "PROJECT_ID:REGION:INSTANCE_NAME"
  #   volumeMounts:
  #   - name: cloudsql
  #     mountPath: /cloudsql

traffic:

  • percent: 100
    latestRevision: true

Alternatively, route traffic to specific revisions:

- percent: 80

revisionName: my-cloudrun-service-rev001

- percent: 20

revisionName: my-cloudrun-service-rev002``

@Tsukimarf
Tsukimarf merged commit 96987ff into main Nov 28, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant