Skip to main content

Kavita on Google Cloud Run

Kavita on Google Cloud Run

Kavita is a fast, self-hosted digital library and reading server for comics, manga, and e-books — a clean web reading UI, OPDS feeds, collections, reading lists, and full-text search over your library, built on .NET with an internal SQLite database. This module deploys Kavita on Cloud Run v2 on top of the App_CloudRun foundation, which provisions and manages the shared Google Cloud infrastructure.

This guide focuses on the cloud services Kavita uses and how to explore and operate them from the Google Cloud Console and the command line. For the mechanics common to every Cloud Run application — service identity, ingress and load balancing, scaling and concurrency, CI/CD, Cloud Armor, IAP, Binary Authorization, VPC Service Controls, backups, and the deployment lifecycle — refer to the App_CloudRun foundation guide rather than repeating them here.


1. Overview

Kavita runs as a single .NET container on Cloud Run v2 with no external database or cache — everything it needs (settings, its internal SQLite database, and the library index) lives on disk under /kavita/config.

CapabilityGoogle Cloud serviceNotes
ComputeCloud Run v2.NET web container on port 5000, 1000m CPU / 1Gi memory by default; min=1/max=1
DatabaseNone — internal SQLitedatabase_type is fixed to NONE by Kavita_Common; no Cloud SQL instance is created
State persistenceCloud Storage bucket mounted via GCS Fuse/kavita/config holds the SQLite database (kavita.db), settings, covers, and logs — this is Cloud Run's only persistence option (no block PVC)
Object storageCloud StorageA storage bucket is auto-provisioned and mounted at /kavita/config
SecretsSecret ManagerNone generated — the first-run setup wizard creates the admin account; secret_ids/secret_values are empty
IngressCloud Run URL / Cloud Load BalancingDefault run.app URL; optional external HTTPS load balancer + custom domain

Sensible defaults worth knowing up front:

  • SQLite has no choice but to live on GCS Fuse here. Cloud Run has no block Persistent Volume option, so /kavita/config (Kavita's SQLite database and settings) is always mounted through gcsfuse. This is the one place in this module where the repository's usual "gcsfuse corrupts SQLite" caution is unavoidable rather than a misconfiguration — the module's own description recommends Kavita_GKE for production libraries, where the same data instead lives on a real block PVC. Treat Kavita_CloudRun as best suited to light-to-medium libraries.
  • min_instance_count defaults to 1, not 0. Unlike most Cloud Run application modules (which default to scale-to-zero), Kavita keeps one instance always warm by default, avoiding cold-start delays while it reloads its library index and re-mounts the gcsfuse volume.
  • max_instance_count is pinned to 1. Kavita has no clustering or shared-write coordination; a second instance writing to the same gcsfuse-mounted SQLite file risks corrupting the library index.
  • No database, no Redis. database_type is fixed to NONE, and Redis is forced off: main.tf hardcodes enable_redis = false regardless of the variable's own inherited foundation default (true) — Kavita has no use for a queue or cache.
  • No auto-generated secrets. There is no admin password, API key, or signing key created in Secret Manager. The administrator account is created interactively through Kavita's first-run setup wizard the first time you open the service URL.
  • Custom-built image, pinned version tag. The Dockerfile thin-wraps jvmilazz0/kavita:${KAVITA_VERSION}. application_version = "latest" resolves to a pinned KAVITA_VERSION = 0.8.7 build argument in Kavita_Common (not the generic APP_VERSION the Foundation injects) — bumping the version requires editing that pinned value and rebuilding, not just redeploying.
  • Health path is /api/health, unauthenticated, for both probes. The startup probe allows a generous failure budget to tolerate first-boot library indexing.
  • Only Kavita's state directory is persisted by this module. The actual library content (comics, manga, e-books) is not provisioned here — add your own gcs_volumes (or NFS) for the content and register it as a library inside the Kavita UI after deploy.

2. Google Cloud Services & How to Explore Them

All commands assume PROJECT and REGION are set. Service and resource names are reported in the deployment Outputs.

A. Cloud Run — the Kavita service

Kavita runs as a single Cloud Run v2 service. Because it is a single-writer SQLite app backed by a gcsfuse-mounted volume, do not raise max_instance_count above 1.

  • Console: Cloud Run → select the service for revisions, traffic, logs, and metrics.
  • CLI:
    gcloud run services list --project "$PROJECT" --region "$REGION"
    gcloud run services describe <service-name> --project "$PROJECT" --region "$REGION"
    gcloud run revisions list --service <service-name> --project "$PROJECT" --region "$REGION"

See App_CloudRun for scaling, concurrency, execution environment, and traffic splitting.

B. Cloud Storage — the GCS Fuse–mounted config/library-state bucket

Kavita_Common provisions a single Cloud Storage bucket (suffix storage) and this module mounts it at /kavita/config via GCS Fuse. It holds Kavita's SQLite database (kavita.db), cover images, bookmarks, backups, and logs — effectively all of Kavita's durable state. Additional buckets can be declared via storage_buckets, and additional read-only content mounts via gcs_volumes.

  • Console: Cloud Storage → Buckets.
  • CLI:
    gcloud storage buckets list --project "$PROJECT" --filter="name~kavita"
    gcloud storage ls gs://<config-bucket>/ # bucket name is in the Outputs

See App_CloudRun for GCS Fuse mount options and CMEK.

C. Secret Manager

Kavita has no generated secrets — no admin password, API key, or signing key is created by this module. Kavita's own JWT signing key (TokenKey) is auto-generated by the application on first boot and persisted on the gcsfuse-mounted /kavita/config volume, not in Secret Manager. Any secrets you add yourself via secret_environment_variables flow through Secret Manager like any other application module.

  • Console: Security → Secret Manager.
  • CLI:
    gcloud secrets list --project "$PROJECT" --filter="name~kavita"

See App_CloudRun for injection and rotation details.

D. Networking & ingress

The service is reachable at its run.app URL by default (ingress_settings = "all"), which allows browsers, mobile reader apps, and OPDS clients to reach it directly. An external HTTPS load balancer with a custom domain, Cloud CDN, and Cloud Armor can be layered on; ingress settings and VPC egress control connectivity.

  • Console: Cloud Run (service URL); Network services → Load balancing.
  • CLI:
    gcloud run services describe <service-name> --region "$REGION" --format='value(status.url)'
    gcloud compute addresses list --project "$PROJECT"

See App_CloudRun.

E. Cloud Logging & Monitoring

Container logs flow to Cloud Logging; Cloud Run metrics flow to Cloud Monitoring, with optional uptime checks and alert policies.

  • Console: Logging → Logs Explorer; Monitoring → Dashboards / Alerting.
  • CLI:
    gcloud run services logs read <service-name> --project "$PROJECT" --region "$REGION" --limit 50

3. Kavita Application Behaviour

  • No first-deploy database setup. Kavita has no db-init job — there is no external database to bootstrap. initialization_jobs defaults to an empty list; only custom jobs you supply are run.
  • No migration step. Kavita creates and migrates its own internal SQLite schema on first boot; upgrading application_version (and rebuilding) applies schema changes automatically without a separate migration job.
  • No immutable, auto-generated secrets. Unlike most application modules, there is no encryption key, admin token, or JWT secret minted into Secret Manager. Kavita's own JWT TokenKey is generated internally on first boot and persisted on the /kavita/config volume — nothing to rotate or lose track of at the Terraform layer.
  • Health path. Both the startup and liveness probes target the public, unauthenticated /api/health endpoint. The startup probe uses a longer failure budget (initial_delay_seconds = 15, period_seconds = 10, failure_threshold = 10) to tolerate slower first-boot library indexing before the liveness probe (initial_delay_seconds = 30, period_seconds = 30, failure_threshold = 3) takes over.
  • Sign-up / first-run behaviour. There is no seeded admin account or generated credential. Open the service URL — Kavita's first-run setup wizard walks through creating the initial administrator account and adding your first library. Complete this promptly after deploy: until it runs, the service is reachable but unclaimed.
  • Redis is force-disabled. main.tf sets enable_redis = false unconditionally when calling App_CloudRun, overriding the foundation's own enable_redis = true default — no REDIS_HOST/REDIS_PORT are ever injected, and the redis_host/redis_port/redis_auth variables have no effect.
  • enable_cloudsql_volume is fixed off. main.tf passes enable_cloudsql_volume = false directly to the foundation regardless of the variable (whose own default is also false) — Kavita has no Cloud SQL Auth Proxy sidecar.
  • Custom image build. The container is built from a thin wrapper Dockerfile (FROM jvmilazz0/kavita:${KAVITA_VERSION}); application_version = "latest" resolves to the pinned KAVITA_VERSION = 0.8.7 build argument (a version bump requires editing the pinned value in Kavita_Common, then a rebuild — see the repository's "latest-tag base images" convention).
  • Inspect the service and its mounted state:
    gcloud run services describe <service-name> \
    --region "$REGION" --project "$PROJECT" \
    --format='value(status.url)'
    gcloud run jobs list --project "$PROJECT" --region "$REGION"
    gcloud run jobs executions list --job <job-name> --project "$PROJECT" --region "$REGION"

4. Configuration Variables

Variables are grouped exactly as they appear on the deployment platform. Only settings specific to or notable for Kavita are listed; every other input is inherited from App_CloudRun with its standard behaviour.

Group 1 — Project & Identity

VariableDefaultDescription
project_id(required)Target Google Cloud project.
regionus-central1Region for the service and regional resources.

Group 2 — Deployment Environment

VariableDefaultDescription
tenant_deployment_iddemoShort suffix that makes resource names unique per environment.
support_users[]Emails granted project access and monitoring alerts.
resource_labels{}Labels applied to all resources.

Group 3 — Application Identity

VariableDefaultDescription
application_namekavitaBase name for resources. Do not change after first deploy.
application_display_nameKavitaHuman-readable name shown in the Console.
descriptionKavita — self-hosted comics, manga and ebook server (.NET, SQLite)Service description.
application_versionlatestKavita image tag; latest resolves to the pinned KAVITA_VERSION = 0.8.7 build arg in Kavita_Common.

Group 4 — Runtime & Scaling

VariableDefaultDescription
deploy_applicationtrueSet false to provision infrastructure only.
cpu_limit1000mCPU per instance; Kavita is a lightweight .NET server.
memory_limit1GiMemory per instance; comfortable for large libraries.
min_instance_count1Kept at 1 by default to avoid cold starts during library index loading — most Cloud Run modules default to 0.
max_instance_count1Keep at 1. No clustering — a second instance writing the same gcsfuse-mounted SQLite file risks corruption.
container_port5000Kavita's fixed HTTP port.
execution_environmentgen2Required for the GCS Fuse mount.
timeout_seconds300Maximum request duration (0–3600 seconds).
enable_cloudsql_volumefalseKavita has no Cloud SQL; also hardcoded false in main.tf regardless of this value.
enable_image_mirroringtrueMirror the Kavita image into Artifact Registry.
container_protocolhttp1HTTP/1.1 is sufficient; Kavita has no gRPC use for h2c.
traffic_split[]Split traffic across revisions for staged rollouts.
max_revisions_to_retain7Declared for convention parity; not referenced by this module's deployment.
service_annotations / service_labels{}Custom annotations/labels on the Cloud Run service resource.

Group 5 — Access & Ingress Control

VariableDefaultDescription
ingress_settingsallPublic access for the reading UI, OPDS feeds, and reader-app clients.
vpc_egress_settingPRIVATE_RANGES_ONLYRoute only RFC 1918 traffic via VPC.
enable_iapfalseRequire Google sign-in. OPDS/mobile reader clients typically cannot complete IAP's auth flow.
iap_authorized_users / iap_authorized_groups[]Who may access through IAP.

Group 6 — Environment Variables & Secrets

VariableDefaultDescription
environment_variables{}Extra non-secret settings; Kavita needs none by default.
secret_environment_variables{}Map of env var → Secret Manager secret name.
secret_propagation_delay30Seconds to wait after secret creation before proceeding.
secret_rotation_period2592000sSecret Manager rotation notification frequency — only relevant to secrets you add yourself; Kavita mints none.

Group 7 — Backup & Restore

VariableDefaultDescription
backup_schedule0 2 * * *Automated backup cron (UTC).
backup_retention_days7Retention; raise for production.
enable_backup_import / backup_source / backup_uri / backup_formatrestore optionsRestore /kavita/config from a backup on deploy — Kavita has no separate database dump; its state is the config directory itself.

Group 8 — CI/CD & Binary Authorization

Standard App_CloudRun Cloud Build / Cloud Deploy integration — see App_CloudRun. Key inputs: enable_cicd_trigger, github_repository_url, github_token, enable_cloud_deploy, enable_binary_authorization.

Group 9 — Custom SQL Scripts & NFS Instance Discovery

VariableDefaultDescription
enable_custom_sql_scriptsfalseNot applicable — Kavita has no SQL database.
custom_sql_scripts_bucket / custom_sql_scripts_path / custom_sql_scripts_use_rootNot applicable.
nfs_instance_name / nfs_instance_base_name"" / app-nfsOnly relevant if you add an NFS mount for separate library content; unused by default.

Group 10 — Cloud Armor, CDN & Image Retention

VariableDefaultDescription
enable_cloud_armorfalseProvision Global HTTPS LB + Cloud Armor WAF.
admin_ip_ranges[]CIDR ranges exempted from WAF rules.
application_domains[]Custom domain names for the HTTPS LB.
enable_cdnfalseEnable Cloud CDN on the HTTPS LB backend.
max_images_to_retain / delete_untagged_images / image_retention_days(set)Artifact Registry cleanup policy.

Group 11 — Storage & Filesystem

VariableDefaultDescription
create_cloud_storagetrueCreates the auto-provisioned storage bucket (mounted at /kavita/config) plus any storage_buckets.
storage_buckets[]Additional GCS buckets beyond the auto-provisioned config bucket.
enable_nfsfalseOff by default; enable only to mount separate library content over NFS.
nfs_mount_path/mnt/nfsMount path for that NFS share (distinct from /kavita/config).
gcs_volumes[]Additional GCS Fuse volume mounts — e.g. a read-only bucket of library content.
manage_storage_kms_iam / enable_artifact_registry_cmekfalseCMEK options.
enable_redis / redis_host / redis_port / redis_authinertDeclared only for Foundation-variable mirroring — main.tf hardcodes enable_redis = false unconditionally; Kavita never uses Redis regardless of these values.

Group 12 — Database Backend (not applicable)

VariableDefaultDescription
database_typeNONEFixed by Kavita_Common — Kavita stores everything in an internal SQLite file; no Cloud SQL instance is created.
database_password_length32Not referenced — Kavita has no SQL database.

All other database-related variables in this group (sql_instance_name, application_database_name/_user, enable_mysql_plugins, enable_postgres_extensions, the db_*_env_var_name set, enable_auto_password_rotation, etc.) are declared only for Foundation-variable mirroring and have no effect on a Kavita deployment.

Group 13 — Jobs & Scheduled Tasks

VariableDefaultDescription
initialization_jobs[]Leave empty — Kavita has no db-init/migration job; it manages its own SQLite schema on first boot.
cron_jobs[]Not used by default; add custom scheduled tasks (e.g. collection snapshots) if needed.

Group 14 — Observability & Health

VariableDefaultDescription
startup_probeHTTP /api/health, 15s delayStartup probe; 10-attempt failure budget tolerates first-boot library indexing.
liveness_probeHTTP /api/health, 30s delayLiveness probe.
startup_probe_config / health_check_configdisabled alt / HTTP /api/healthAlternative structured probes (inactive by default; startup_probe/liveness_probe take effect).
uptime_check_config{ enabled=false, path="/api/health" }Cloud Monitoring uptime check; disabled by default.
alert_policies[]Metric alert policies.

Group 15 — Networking

VariableDefaultDescription
network_name""Declared for convention mirroring; not forwarded to App_CloudRun by this module — the VPC network is auto-discovered instead.

Group 23 — VPC Service Controls & Audit Logging

VariableDefaultDescription
enable_vpc_scfalseEnforce a VPC-SC perimeter (requires organization_id).
vpc_cidr_ranges / vpc_sc_dry_run(set)Access level CIDRs / dry-run mode.
enable_audit_loggingfalseDetailed Cloud Audit Logs.

5. Outputs

Returned on a successful deployment — the quickest way to locate and explore the running resources.

OutputDescription
service_nameCloud Run service name.
kavita_urlInternal VPC URL for the Kavita service (port 5000); only reachable within the VPC when ingress_settings = "internal".
service_locationRegion the service runs in.
stage_servicesStage-specific service URLs (Cloud Deploy).
load_balancer_ip / load_balancer_urlExternal HTTPS load balancer IP / URL (when enabled).
storage_bucketsCreated Cloud Storage buckets, including the storage bucket mounted at /kavita/config.
network_name / network_exists / regionsVPC network, presence, regions.
container_image / container_registryDeployed image and Artifact Registry repo.
monitoring_enabled / monitoring_notification_channels / uptime_check_namesMonitoring status, channels, uptime checks.
initialization_jobsNames of any custom initialization jobs you supplied (none by default).
deployment_id / tenant_id / resource_prefixNaming identifiers.
project_id / project_numberProject identifiers.
cicd_enabled / github_repository_url / github_repository_owner / github_repository_name / cicd_configurationCI/CD status and details.
artifact_registry_repository / cloudbuild_trigger_name / cloudbuild_trigger_idRegistry and build trigger.
vpc_sc_enabled / vpc_sc_perimeter_name / vpc_sc_dry_run_modeVPC-SC status.
audit_logging_enabled / artifact_registry_cmek_enabledAudit logging and CMEK status.

Note there are no database_* outputs — Kavita provisions no Cloud SQL instance.


6. Configuration Pitfalls & Sensible Defaults

Risk: Critical (data loss / outage / security) — High (service degraded) — Medium (cost or partial degradation) — Low (minor).

Inherited plan-time validation. This module passes its configuration through the App_CloudRun foundation engine, which validates values and combinations at plan time — a read replica without its primary, IAP with no authorized identities, a gen1 runtime with a GCS Fuse mount, an out-of-range redis_port/backup_retention_days. Invalid configuration fails the plan with a clear, named error before any resource is created, so most mistakes below are caught up front rather than at apply or runtime.

SettingSensible valueRiskConsequence if wrong
/kavita/config on GCS FuseAccept for light/medium libraries onlyCriticalGCS Fuse is Cloud Run's only persistence option; concurrent writes or heavy metadata scans against a gcsfuse-backed SQLite file risk corrupting the library index. For large libraries, use Kavita_GKE's block PVC instead.
max_instance_count1CriticalKavita has no clustering; a second instance writing to the same gcsfuse-mounted SQLite file corrupts the library index and admin/user data.
Library content storageAdd gcs_volumes (or NFS) separate from /kavita/configHighKavita_Common only persists the config/SQLite state directory — without a separate mount for the actual comics/manga/e-book files, there is nowhere durable to store the library content itself.
enable_iapfalse unless all clients support itHighKavita's OPDS feed and mobile reader-app clients typically cannot complete Google IAP's auth flow, so enabling IAP breaks e-reader access even though the browser UI still works via a browser challenge.
ingress_settingsallHighinternal blocks the reading UI and OPDS clients from reaching the service directly.
First-run admin accountComplete the setup wizard immediately after deployMediumUntil the wizard runs, the service is reachable but unclaimed — anyone who reaches the URL first can create the initial admin account.
application_version / KAVITA_VERSIONPin explicitly for productionMedium"latest" resolves to Kavita_Common's pinned KAVITA_VERSION = 0.8.7; bumping requires editing that pinned value and rebuilding, not just redeploying.
min_instance_count1 (default)MediumSetting to 0 enables scale-to-zero but adds cold-start latency while gcsfuse re-mounts and Kavita reloads its library index.
enable_redis (inert)leave as-isLowSetting this variable has no effect — main.tf hardcodes enable_redis = false regardless of the value passed.
enable_cloudsql_volumefalseLowKavita never uses Cloud SQL; the value is hardcoded false in main.tf regardless of this setting.
backup_retention_days7 (raise for prod)MediumToo short for compliance retention; Kavita's entire state is the /kavita/config directory, so this is the only backup path.

For the foundation behaviour referenced throughout — service identity, scaling and concurrency, ingress and load balancing, CI/CD, Cloud Armor, IAP, Binary Authorization, VPC-SC, backups, and image mirroring — see App_CloudRun. Kavita's application-specific configuration shared with the GKE variant — including why it has no generated secrets, no database, and how the /kavita/config state directory is mounted differently on each platform (GCS Fuse here vs. a block PVC on GKE) — is described in Kavita_Common.