shlink-backend
A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own domain.
About this chart
shlink-backend
A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own domain.
TL;DR;
helm repo add christianhuth https://charts.christianhuth.de
helm repo update
helm install my-release christianhuth/shlink-backend
Or install it from the OCI registry:
helm install my-release oci://ghcr.io/christianhuth/helm-charts/shlink-backend
Introduction
This chart bootstraps a self-hosted URL shortener called Shlink using the Helm package manager.
Prerequisites
- Kubernetes 1.29+
- The CloudNativePG operator if the bundled PostgreSQL database is used (
postgresql.enabled: true) - The mariadb-operator if the bundled MariaDB database is used (
mariadb.enabled: true)
Shlink uses SQLite by default, which needs neither of them. RabbitMQ (cloudpirates/rabbitmq) and Valkey (valkey/valkey) are bundled as regular subcharts and don't need an operator.
Installing the operators
The operators are not part of this chart, as they are installed once per Kubernetes cluster:
# CloudNativePG, for postgresql.enabled
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install cnpg cnpg/cloudnative-pg --namespace cnpg-system --create-namespace --wait
# mariadb-operator, for mariadb.enabled
helm upgrade --install mariadb-operator-crds oci://ghcr.io/mariadb-operator/charts/mariadb-operator-crds --namespace mariadb-operator --create-namespace
helm upgrade --install mariadb-operator oci://ghcr.io/mariadb-operator/charts/mariadb-operator --namespace mariadb-operator --wait
Installing the Chart
To install the chart with the release name my-release:
helm repo add christianhuth https://charts.christianhuth.de
helm repo update
helm install my-release christianhuth/shlink-backend
The chart is also published as an OCI artifact which can be installed like this:
helm install my-release oci://ghcr.io/christianhuth/helm-charts/shlink-backend
These commands deploy Shlink on the Kubernetes cluster in the default configuration. The Values section lists the values that can be configured during installation.
Tip: List all releases using
helm list
Uninstalling the Chart
To uninstall the my-release deployment:
helm uninstall my-release
The command removes all the Kubernetes components associated with the chart and deletes the release.
Configuring the Dependencies
Shlink uses SQLite by default and optionally a database server, a Redis-compatible cache and RabbitMQ for real-time updates. Each of them is either bundled with the chart or provided externally. Passwords are read from Secrets, using existing Secrets is recommended for production.
PostgreSQL
kubectl create secret generic shlink-database \
--type=kubernetes.io/basic-auth \
--from-literal=username=shlink \
--from-literal=password='<password>'
postgresql:
enabled: true
cluster:
initdb:
database: shlink
owner: shlink
secret:
name: shlink-database
The username in the Secret has to match postgresql.cluster.initdb.owner. If no Secret is referenced, the operator generates the Secret <release>-postgresql-app. See the values of the upstream chart for all options.
MariaDB
kubectl create secret generic shlink-database --from-literal=password='<password>'
mariadb:
enabled: true
mariadb:
passwordSecretKeyRef:
name: shlink-database
key: password
generate: false
If no Secret is referenced, the operator generates the Secret <release>-mariadb-password. By default the database runs as a Galera cluster with 3 instances. To upgrade to another MariaDB release series, change the tag of mariadb.mariadb.image; the operator migrates the system schema, but downgrades are not supported. See the values of the upstream chart for all options.
Only one bundled database can be enabled at a time.
Valkey
valkey:
enabled: true
Valkey runs without authentication by default. To require a password for the user default, which Shlink authenticates as:
kubectl create secret generic shlink-valkey --from-literal=password='<password>'
valkey:
enabled: true
auth:
enabled: true
usersExistingSecret: shlink-valkey
aclUsers:
default:
permissions: "~* &* +@all"
passwordKey: password
Shlink receives the password as part of its Redis server URL, so it must only contain URL-safe characters (A-Z, a-z, 0-9, -, ., _, ~). See the values of the upstream chart for all options.
RabbitMQ
kubectl create secret generic shlink-rabbitmq \
--from-literal=password='<password>' \
--from-literal=erlang-cookie='<random string>'
rabbitmq:
enabled: true
auth:
username: shlink
existingSecret: shlink-rabbitmq
existingPasswordKey: password
If no Secret is referenced, the chart generates a random password and Erlang cookie in the Secret <release>-rabbitmq. By default RabbitMQ runs as a cluster of 3 instances. See the values of the upstream chart for all options.
External Services
externalDatabase:
type: postgres # mysql, maria, postgres or mssql
hostname: postgresql.example.com
database: shlink
username: shlink
existingSecret: shlink-database
existingSecretPasswordKey: password
externalRedis:
hostname: redis.example.com
port: 6379
existingSecret: shlink-redis
existingSecretPasswordKey: password
externalRabbitmq:
hostname: rabbitmq.example.com
username: shlink
existingSecret: shlink-rabbitmq
existingSecretPasswordKey: password
Instead of existingSecret you can set password, which lets the chart create the Secret. As for Valkey, the Redis password must only contain URL-safe characters. For Redis Sentinel, point externalRedis.hostname to a Sentinel instance and set externalRedis.sentinelService.
Values
| Key | Type | Default | Description |
|---|---|---|---|
| affinity | object | {} | Affinity settings for pod assignment |
| autoscaling.enabled | bool | false | |
| autoscaling.maxReplicas | int | 100 | |
| autoscaling.minReplicas | int | 1 | |
| autoscaling.targetCPUUtilizationPercentage | int | 80 | |
| config.database.useEncryption | bool | false | Whether it is desired to use an encrypted connection with the database or not |
| config.general.basePath | string | "" | The base path from which you plan to serve Shlink, in case you don’t want to serve it from the root of the domain. It has to start with a bar, like /shlink. Defaults to ''. |
| config.general.cacheNamespace | string | "" | A prefix used for all cache keys generated by Shlink. It’s important to set a unique value here if you have multiple Shlink instances sharing the same cache store (same server when not using redis, or same redis cluster), otherwise there could be collisions. Defaults to Shlink. |
| config.general.defaultDomain | string | "" | The default short domain used for this Shlink instance. For example s.test. |
| config.general.initialApiKey | string | "" | An API key that will be created once during container start-up, with admin permissions. |
| config.general.isHttpsEnabled | bool | false | Tells if Shlink is served with https or not (true or false). It’s still up to you to actually serve it with HTTPS. |
| config.general.memoryLimit | string | "" | The maximum amount of memory that every Shlink process can use. You can provide a number, which will be the amount of memory in bytes, or a number followed by K for kilobytes, M for megabytes or G for gigabytes. You can also provide -1 to set no memory limit. Defaults to 512M. |
| config.general.timezone | string | "" | A timezone code as defined in this list. All dates stored by Shlink (visits, short URL creation, etc) will be considered to be on this timezone. By default, the default timezone set in PHP config will be used, which is UTC in the case of the docker image. |
| config.geolite.licenseKey | string | "" | The license key used to download new GeoLite2 database files. Go to GeoLite2 license key to know how to generate it. Not providing a license key will completely disable visits geolocation. |
| config.geolite.skipInitialDownload | bool | false | If provided with value true, it will skip the initial GeoLite2 db file download, speeding-up the container start-up. As a side effect, first visits on this container will remain un-located until the file finishes downloading in background. |
| config.matomo.auth.apiToken | string | "" | The API token so that Shlink can call Matomo’s API |
| config.matomo.auth.existingSecret | string | "" | Use existing secret for the API token details (config.matomo.auth.apiToken will be ignored and picked up from this secret). The secret has to contain the key api-token. |
| config.matomo.baseUrl | string | "" | The external Matomo server URL. |
| config.matomo.enabled | bool | false | Enable the Matomo integration to sent visits |
| config.matomo.siteId | string | "" | The site ID to be used for Shlink visits. |
| config.mercure.auth.existingSecret | string | "" | Use existing secret for the JWT secret details (config.mercure.auth.jwtSecret will be ignored and picked up from this secret). The secret has to contain the key jwt-secret. |
| config.mercure.auth.jwtSecret | string | "" | The secret key that was provided to the mercure hub server, in order to be able to generate valid JWTs for publishing/subscribing to that server. |
| config.mercure.enabled | bool | false | Enable the Mercure Hub integration. |
| config.mercure.internalHubUrl | string | "" | An internal URL for a mercure hub. Will be used only when publishing updates to mercure, and does not need to be public. |
| config.mercure.publicHubUrl | string | "" | The public URL of a mercure hub server to which Shlink will sent updates. This URL will also be served to consumers that want to subscribe to those updates. |
| config.qrCodes.codeForDisabledShortUrls | bool | true | Whether generating QR codes should work for disabled short URLs. Disabled short URLs are those which reached the maximum amount of visits, have a validSince date in the future, or a validUntil date in the past. |
| config.qrCodes.defaultColors.background | string | "#FFFFFF" | The QR code background color. |
| config.qrCodes.defaultColors.foreground | string | "#000000" | The QR code foreground color. |
| config.qrCodes.defaultErrorCorrection | string | "l" | One of L (Low), M (Medium), Q (Quartile) or H (High), to determine the default error correction of generated QR codes when the errorCorrection query param is not provided. |
| config.qrCodes.defaultFormat | string | "png" | One of png or svg, to determine the default format of generated QR codes when the format query param is not provided. |
| config.qrCodes.defaultLogoUrl | string | "" | A URL pointing to a logo that will be placed in the middle of the QR code. This one is experimental, as some images might break the QR code. |
| config.qrCodes.defaultMargin | int | 0 | A value greater than 0 to determine the default margin of generated QR codes when the margin query param is not provided. |
| config.qrCodes.defaultRoundBlockSize | bool | true | Tells if the block size should be round on QR codes, making it more readable, but potentially adding some extra margin as a side effect. |
| config.qrCodes.defaultSize | int | 300 | A value between 50 and 1000 to determine the default size of generated QR codes when the size query param is not provided. |
| config.redirects.cacheLifetime | int | 30 | Allows to set the amount of seconds that redirects should be cached when redirect status is 301 or 308. |
| config.redirects.defaultBaseUrlRedirect | string | "" | If a URL is provided here, when a user tries to access Shlink’s base URL, and the visited domain does not have a redirect URL of its own, he/she will be redirected to this value. If this env var is not provided, the user will see a generic 404 - not found page. |
| config.redirects.defaultInvalidShortUrlRedirect | string | "" | If a URL is provided here, when a user tries to access an invalid short URL, and the visited domain does not have a redirect URL of its own, he/she will be redirected to this value. If this env var is not provided, the user will see a generic 404 - not found page. |
| config.redirects.defaultRegular404Redirect | string | "" | If a URL is provided here, when a user tries to access a URL not matching any supported by the router, and the visited domain does not have a redirect URL of its own, he/she will be redirected to this value. If this env var is not provided, the user will see a generic 404 - not found page. |
| config.redirects.extraPathMode | string | "default" | Determines how Shlink should match short URLs when they start with a known short code. Valid values are default, append and ignore. (See Extra path forwarding for more info). |
| config.redirects.statusCode | int | 302 | 301, 302, 308 or 307 (last two since v3.5.0). Determines the status code that should be used on redirects from shor |
Deploy shlink-backend with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has shlink-backend on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartshlink-backend is pinned at v12.0.8 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply