Skip to main content

Shlink on GKE Autopilot

Shlink on GKE Autopilot

Shlink is a self-hosted, open-source URL shortener that exposes a REST API, a web client, QR code generation, and detailed visit-tracking analytics. This module deploys Shlink on GKE Autopilot on top of the App_GKE foundation, which provisions and manages the shared Google Cloud and Kubernetes infrastructure.

This guide focuses on the cloud services Shlink uses and how to explore and operate them from the Google Cloud Console and the command line. For the mechanics that are common to every GKE application — Workload Identity, ingress, autoscaling, CI/CD, Cloud Armor, IAP, Binary Authorization, VPC Service Controls, backups, and the deployment lifecycle — refer to the App_GKE foundation guide rather than repeating them here.


Running Shlink in your own GCP project costs about $91.31/month in Google Cloud charges; RAD's module fee is a one-time 75 credits (or 67.5 credits in a RAD-managed project), covering setup and support -- not the ongoing cloud bill, which Google bills you directly in your own project or RAD meters hourly in credits in a RAD-managed one. If a lower running cost matters more than the deployment target, see the Cloud Run guide for the lower-cost option; otherwise, if you deploy into a RAD-managed project you can pause the whole thing for free when you are not using it -- see Pause it for free below.

What you pay on RAD​

Your own projectRAD-managed project
Module fee75 credits, once67.5 credits, once (10% lower)
Build timemetered in credits as the build runs (a few credits, typically)same
Google Cloud running cost~$91.31/month, billed to your own billing account at Google's list price~91 credits/day, metered hourly by RAD at list price plus margin

Default running cost in your own project

ResourceUS$/month (Google list price, us-central1)
GKE Autopilot pod, 1x vCPU / 0.5 GiB$34.29
Cloud SQL for PostgreSQL, 1 vCPU / 3.75 GB, zonal, 10 GB SSD$51.02
Cloud NAT and networking$5.00
Cloud Storage (add-ons, backups)$1.00
GKE cluster management feeshared across every GKE app in the project; $0 if this is your only cluster, else ~$73
Total$91.31

How it compares​

  • Shlink's own footprint here (1x vCPU / 0.5 GiB) is smaller than this reference class, so an even cheaper VPS tier would do just as well, but sized to the smallest commonly-quoted class for comparison: Hetzner CPX22 (2 vCPU/4GB) runs about $24/month, a DigitalOcean 2 vCPU/4GB Droplet is also $24/month, and a GCP Compute Engine e2-standard-2 (2 vCPU/8GB) is about $49/month -- plus the admin's own time for backups, security patches and upgrades, which RAD's managed Cloud SQL, Secret Manager and monitoring cover for you -- but RAD's price is never meant to beat a VPS, only to replace the admin time a VPS still needs.
  • A URL shortener answers simple redirects continuously but cheaply -- the database is the main standing cost here, not the shortener service itself.

Pause it for free: delete a RAD-managed project, restore it when you need it​

This is the headline for a RAD-managed project. Deleting a RAD-managed project first unlinks its billing, then asks Google to delete the project outright -- Google's own 30-day recoverable soft delete. Unlike deleting one module, this does not tear down Cloud SQL, any VM or the compute resource one by one: the whole project simply stops, and nothing is charged while it waits, because billing is already unlinked.

Restoring, within 30 days and only by the project's owner, asks Google to undelete the project and reattaches its billing account, then asks you to run Update on each deployment to confirm everything came back. Because nothing was individually destroyed, that Update finds the same resources already there -- it is a check, not a rebuild, and an Update never charges the module fee again. This costs only a handful of credits (under US$1) in total for a typical 2-3-deployment chain.

What this needs: you must own the project (not one RAD only manages billing for), you must restore it yourself within 30 days -- after that Google deletes it for good -- and restoring is admitted like creating a new project, so your purchased credit balance must still clear the tier's floor (100 credits for the sandbox tier most study/demo use fits). Google says most services are fully working again within 36 hours of a restore.

One real gap: nightly backups are written to a bucket inside the project, and that bucket has Cloud Storage's soft-delete explicitly turned off, so it is very likely gone as soon as you delete the project -- even though the project itself is recoverable for 30 days. If you have customised the app and want to keep that work, copy a backup out (to Google Drive, or a bucket outside the project) before deleting. For a default install with nothing irreplaceable in it, this does not matter.

Pay only while you use it, the other way: delete and redeploy​

In your own project (or once you are past the 30-day restore window above), the alternative is to delete Shlink outright and redeploy it later. A redeploy costs the module fee again, plus the builds -- roughly 75 + 3-6 credits of build time.

Deleting saves money only once Shlink would otherwise sit unused long enough to clear that redeploy cost against its own daily running cost -- against the own-project total above, that works out to about 3 days or more. Most of the running cost here is usually the database; it stops only when nothing else in the project uses it, so deleting this app while something else shares the project saves only this app's own compute part.

Keep data first: nightly backups go to a bucket inside the deployment and are deleted with it, so copy the latest backup out before deleting if you want to keep it.

Lab sessions and Managed Environments​

  • Lab sessions, for training: a trainer runs a session for a class. Each participant gets the app in their own Google Cloud project for 15 minutes to 24 hours, within an allowance the trainer sets. Either the trainer funds every place, or each participant pays for their own. Everything is deleted when the session ends and unused credits go back to the trainer.
  • Managed Environments, for consultancies: a partner runs the app for a client from a ring-fenced wallet it funds, and settles with the client directly. If the wallet runs low, billing pauses and the data is kept, so nobody receives an unexpected charge. At the end the partner hands the project over and the deployments become the client's own.
  • Credits can be bought in more than 20 currencies, including XAF, XOF, NGN, GHS, KES and ZAR, by card, bank transfer or mobile money.

Sources (8 October 2026): Google Cloud Billing Catalog API list prices; radmodules.dev/pricing for RAD's own fees and daily-credit estimates; https://cloud.google.com/resource-manager/docs/delete-restore-projects for the pause/restore mechanics.

1. Overview​

Shlink runs as a single stateless PHP/Swoole workload with all state in PostgreSQL — there is no filesystem persistence to manage.

CapabilityGoogle Cloud serviceNotes
ComputeGKE AutopilotA single container on port 8080, 1000m CPU / 512Mi memory by default
DatabaseCloud SQL for PostgreSQL 15Required — the engine is fixed at POSTGRES_15
Object storageCloud StorageNone provisioned — Shlink stores everything in PostgreSQL
SecretsSecret ManagerAuto-generated INITIAL_API_KEY (first REST API key) and the database password
IngressCloud Load BalancingExternal LoadBalancer with a reserved static IP; optional custom domain + managed certificate

Sensible defaults worth knowing up front:

  • PostgreSQL 15 is mandatory. database_type = "POSTGRES_15" is fixed by the Common module; other engines are not supported.
  • Cloud SQL is reached via the Auth Proxy sidecar on loopback. enable_cloudsql_volume = true injects a cloud-sql-proxy sidecar; App_GKE then sets DB_HOST = DB_IP = 127.0.0.1. Shlink reads DB_HOST/DB_USER/ DB_NAME/DB_PASSWORD directly from the environment — no entrypoint remapping is needed.
  • DB_NAME/DB_USER are intentionally left unset by the Common module. The foundation creates the Cloud SQL role/database under its own tenant-scoped naming convention and injects the real values; presetting them to the short shlink/shlink names would authenticate as a never-created role.
  • No persistent filesystem. gcs_volumes defaults to [] and NFS is not wired in — Shlink stores short URLs, visits, and API keys entirely in PostgreSQL, so there is nothing to persist outside the database.
  • Database migrations run automatically on container start. The official shlinkio/shlink image runs its own schema migrations at boot; there is no separate migrate job (only db-init, which creates the role/database).
  • INITIAL_API_KEY is generated automatically and stored in Secret Manager, then injected as a container secret env var so Shlink bootstraps its first REST API key on initial start. Retrieve it after deploy — Shlink has no admin username/password login; all access is API-key based.
  • The Dockerfile always builds FROM shlinkio/shlink:stable — unlike most custom-build modules in this repository, application_version is not wired into the image tag via a build ARG (container_build_config keeps build_args = {}). Changing application_version has no effect on which image is built. Pin a specific release by editing the Common module's Dockerfile FROM line directly.
  • Scales 1→3 pods by default (min_instance_count = 1, max_instance_count = 3). Shlink is stateless per-request against PostgreSQL, so horizontal scaling is safe out of the box.
  • DEFAULT_DOMAIN is not preset. The public hostname used when generating short URLs is unknown until after deploy — set it via environment_variables once the LoadBalancer IP or custom domain is known.

2. Google Cloud Services & How to Explore Them​

All commands assume you have run gcloud container clusters get-credentials <cluster> --region <region> --project <project> and that PROJECT, REGION, and NAMESPACE are set. The namespace and other identifiers are reported in the deployment Outputs.

Shlink pods are scheduled on Autopilot, which bills for the CPU/memory the pods actually request. The workload has no persistent storage, so it deploys as a standard Deployment with the default RollingUpdate strategy.

  • Console: Kubernetes Engine → Workloads → select the Shlink workload for pods, revisions, and events. Kubernetes Engine → Services & Ingress shows the external IP.
  • CLI:
    kubectl get pods,svc -n "$NAMESPACE"
    kubectl logs -n "$NAMESPACE" deploy/<service-name> --tail=100
    kubectl describe pod -n "$NAMESPACE" -l app=<service-name>

See App_GKE for how Autopilot, scaling, and the workload type (Deployment vs StatefulSet) are managed.

B. Cloud SQL for PostgreSQL 15​

Shlink stores all application data (short URLs, visit records, tags, and API keys) in a managed Cloud SQL for PostgreSQL 15 instance. Pods reach it through the Cloud SQL Auth Proxy sidecar on 127.0.0.1:5432; no public IP is exposed. On first deploy the db-init job (using postgres:15-alpine) idempotently creates the application role and database, grants ownership and privileges, then shuts down its own proxy sidecar via the quitquitquit endpoint.

  • Console: SQL → select the instance for connections, backups, flags, metrics.
  • CLI:
    gcloud sql instances list --project "$PROJECT"
    gcloud sql instances describe <instance-name> --project "$PROJECT"
    gcloud sql connect <instance-name> --user=<db-user> --database=<db-name> --project "$PROJECT"

The instance name, database, user, and the Secret Manager secret holding the password are all in the Outputs. See App_GKE for the connection model, automated backups, and password rotation.

C. Secret Manager​

Two secrets back the deployment: INITIAL_API_KEY (Shlink's first REST API key, auto-generated by Shlink_Common and injected as a secret env var so the app bootstraps it on first start) and the database password (managed by the foundation). On GKE, secrets are projected into pods via the Secret Store CSI driver / SecretSync.

  • Console: Security → Secret Manager.
  • CLI:
    gcloud secrets list --project "$PROJECT" --filter="name~shlink"
    gcloud secrets versions access latest --secret=<initial-api-key-secret-name> --project "$PROJECT"

See App_GKE for the Secret Store CSI integration and rotation.

D. Networking & ingress​

By default the workload is exposed through an external Cloud Load Balancing IP (service_type = LoadBalancer, reserve_static_ip = true so the address survives redeploys). A custom domain with a Google-managed certificate can be enabled.

  • Console: Network services → Load balancing; VPC network → IP addresses.
  • CLI:
    kubectl get svc,ingress -n "$NAMESPACE"
    gcloud compute addresses list --project "$PROJECT"

See App_GKE for custom domains, Cloud CDN, and static IP details.

E. Cloud Logging & Monitoring​

Pod stdout/stderr flow to Cloud Logging; GKE and Cloud SQL metrics flow to Cloud Monitoring. Optional uptime checks and alert policies are available.

  • Console: Logging → Logs Explorer; Monitoring → Dashboards / Alerting.
  • CLI:
    gcloud logging read 'resource.type="k8s_container" AND resource.labels.namespace_name="'"$NAMESPACE"'"' \
    --project "$PROJECT" --limit 50

  • First-deploy database setup. The db-init job runs db-init.sh using postgres:15-alpine. It waits for PostgreSQL to be reachable, then idempotently CREATEs (or ALTERs) the application role and database, grants ownership and ALL PRIVILEGES, and grants ALL ON SCHEMA public. The job is safe to re-run (execute_on_apply = true). It authenticates as postgres using the same secret as the app's own DB_PASSWORD (ROOT_PASSWORD and DB_PASSWORD both reference database_password_secret).
  • Database migrations run at boot, no separate migrate job. The official shlinkio/shlink image runs its own schema migrations on container start against the empty database created by db-init; there is no execute_on_apply migrate step to wait on beyond db-init itself.
  • No admin account — API-key based access. Shlink does not have an admin username/password. Shlink_Common generates INITIAL_API_KEY and injects it as a secret env var; the image reads it on first start to seed the first valid REST API key. Retrieve it from Secret Manager (see 2.C) and use it as the X-Api-Key header against the REST API or the web client login.
  • DB connectivity is loopback via the Auth Proxy sidecar. With enable_cloudsql_volume = true (default), App_GKE injects DB_HOST = DB_IP = 127.0.0.1; Shlink reads DB_HOST, DB_USER, DB_NAME, and DB_PASSWORD directly — no socket-path or URL-DSN handling is needed.
  • Health path. Both the startup and liveness probes are HTTP GET /rest/health — an unauthenticated, public endpoint that returns HTTP 200 with {"status":"pass"} (application/health+json). There is no web homepage at / (it 404s), so use /rest/health for manual checks too. failure_threshold = 30 at period_seconds = 10 on the startup probe covers ~300s for first-boot migrations.
  • Stateless — safe to scale horizontally. All state lives in PostgreSQL, so the default min_instance_count = 1 / max_instance_count = 3 and the standard RollingUpdate deployment strategy are both safe without further tuning.
  • Set DEFAULT_DOMAIN after the IP/domain is known. It is not preset — add it via environment_variables once the LoadBalancer IP or custom domain is assigned, so generated short URLs use the correct public host:
    kubectl set env deploy/<service-name> -n "$NAMESPACE" DEFAULT_DOMAIN=shlink.example.com
  • Optional visit geolocation. Shlink can resolve visitor geolocation via a MaxMind GeoLite2 database if a GEOLITE_LICENSE_KEY is supplied; it is not set by this module — add it via environment_variables if geolocation is desired.
  • Inspect the init job and running config:
    kubectl get jobs -n "$NAMESPACE"
    kubectl logs -n "$NAMESPACE" job/<db-init-job-name>
    kubectl exec -n "$NAMESPACE" deploy/<service-name> -- env | grep DB_
    curl -s http://<external-ip-or-domain>/rest/health

4. Configuration Variables​

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

Group 3 — Application & Database Identity​

VariableDefaultDescription
application_nameshlinkBase name for resources. Do not change after first deploy.
application_versionlatestNot wired into the image build — the Dockerfile always builds FROM shlinkio/shlink:stable.
admin_usernameshlinkNot used by Shlink (API-key auth, not admin accounts). Retained for wrapper interface parity.

Group 4 — Runtime & Scaling​

VariableDefaultDescription
container_image_sourcecustomCloud Build builds the thin shlinkio/shlink:stable wrapper image.
container_imageshlinkio/shlink:stableUsed only when container_image_source = "prebuilt".
container_port8080Shlink's HTTP server listens on 8080.
container_resources.cpu_limit1000m1 vCPU.
container_resources.memory_limit512MiSufficient for the Swoole-based PHP runtime.
min_instance_count1Minimum pod replicas (HPA minReplicas).
max_instance_count3Maximum pod replicas — safe to raise since Shlink is stateless.
enable_cloudsql_volumetrueAuth Proxy sidecar (loopback) — required on GKE.
cloudsql_volume_mount_path/cloudsqlUnix socket mount path for the proxy sidecar.

Group 6 — GKE Backend & Cluster​

VariableDefaultDescription
service_typeLoadBalancerExternal IP for the Shlink REST API and web client.
workload_typenull → DeploymentDeployment (stateless, RollingUpdate strategy).
session_affinityClientIPSticky routing so a client reaches the same pod.

Group 14 — Cloud Storage​

VariableDefaultDescription
create_cloud_storagetrueNo buckets defined by the Common module — Shlink needs none.
gcs_volumes[]Empty by default — Shlink stores all data in PostgreSQL and needs no persistent filesystem.

Group 16 — Database Backend​

VariableDefaultDescription
database_typePOSTGRES_15Fixed — the only supported engine.
application_database_nameshlinkDatabase name. Immutable after first deploy.
application_database_usershlinkApplication database user; password auto-generated in Secret Manager.

Group 22 — Observability & Health​

VariableDefaultDescription
startup_probe_configHTTP /rest/health, failure_threshold=30, period_seconds=10Public, unauthenticated — covers ~300s for first-boot migrations.
health_check_configHTTP /rest/health, failure_threshold=3, period_seconds=30Liveness probe; same public endpoint.
uptime_check_configenabled=false, path=/rest/healthEnable for an external Cloud Monitoring uptime check.

All other inputs follow standard App_GKE behaviour.


5. Outputs​

These values are returned on a successful deployment and are the quickest way to locate and explore the running resources.

OutputDescription
service_nameKubernetes Service name.
namespaceNamespace the workload runs in.
service_cluster_ipIn-cluster ClusterIP.
stage_service_cluster_ipsMap of ClusterIPs for stage-specific services.
service_external_ipExternal LoadBalancer IP (when a static IP is reserved).
api_urlURL to reach Shlink.
health_check_urlReady-to-curl health-check URL (/rest/health) — use this, not /, which 404s.
database_instance_nameCloud SQL instance name.
database_name / database_userApplication database name / user.
database_password_secretSecret Manager secret holding the DB password.
database_host / database_portDB endpoint (127.0.0.1 via the Auth Proxy) / port.
storage_bucketsCreated Cloud Storage buckets (empty for Shlink).
network_name / network_exists / regionsVPC network, presence, available regions.
container_image / container_registryDeployed image and Artifact Registry repo.
monitoring_enabled / monitoring_notification_channelsMonitoring status and channels.
initialization_jobs / db_import_jobNames of the setup (db-init) and (optional) import jobs.
deployment_id / tenant_id / resource_prefixNaming identifiers.
project_id / project_numberProject identifiers.
cicd_enabled / cicd_configurationCI/CD status and details (repo, trigger, registry).
github_repository_url / github_repository_owner / github_repository_nameCI/CD GitHub details.
artifact_registry_repository / cloudbuild_trigger_name / cloudbuild_trigger_idRegistry and build trigger.
kubernetes_readyWhether the cluster/workload is ready.
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.

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_GKE foundation engine, which validates values and combinations at plan time — a StatefulSet forced alongside a stateless setting, IAP with no authorized identities, quota_memory_* given as bare integers, an out-of-range container_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
database_typePOSTGRES_15 (fixed)CriticalNot overridable — Shlink only supports PostgreSQL.
application_database_name / application_database_userSet onceCriticalImmutable after first deploy; renaming recreates the DB/user and orphans all short URLs and visit history.
environment_variables (DB_NAME/DB_USER)Do not set manuallyCriticalOverriding these to the short shlink/shlink names bypasses the foundation's tenant-scoped role, causing password authentication failed.
enable_cloudsql_volumetrueHighThe Auth Proxy sidecar on 127.0.0.1:5432 is required for DB connectivity on GKE.
INITIAL_API_KEY (auto-generated)Retrieve after deployHighShlink has no admin login — losing track of this secret without rotating it locks you out of the REST API and web client.
startup_probe_config / health_check_config path/rest/healthHighPointing probes at / (404) or an authenticated endpoint prevents the pod from ever becoming Ready.
max_instance_count3 (or higher)LowShlink is stateless; scaling beyond 3 is safe if traffic warrants it — no shared-storage/lock risk.
DEFAULT_DOMAIN (set post-deploy)External LoadBalancer/domain URLMediumA wrong or missing domain makes generated short URLs point at the wrong host.
memory_limit512MiMediumThe gen2/Autopilot memory floor and Swoole runtime needs; raise if pods OOM under sustained load.
quota_memory_requests / _limitsbinary units (4Gi, 8192Mi)CriticalBare integers are treated as bytes and block all pod scheduling in the namespace.
reserve_static_iptrueMediumWithout it, the external IP can change across redeploys, breaking DNS and any hardcoded DEFAULT_DOMAIN.
backup_retention_days7 (raise for prod)MediumToo short for compliance retention of short-URL and visit history data.

For the foundation behaviour referenced throughout — IAM and Workload Identity, autoscaling, ingress and certificates, CI/CD, Cloud Armor, IAP, Binary Authorization, VPC-SC, backups, and image mirroring — see App_GKE. Shlink-specific application configuration shared with the Cloud Run variant is described in Shlink_Common.

Need RAD to do something it does not do yet? Request it on the roadmap, or vote on what is already there.