Skip to content

Building a basic app ​

The app.yml file defines what runs when the app is installed. It is a simplified format inspired by Docker Compose, which n5i converts into Kubernetes objects such as Deployments, Services, Secrets and network policies.

A minimal app ​

yaml
version: 1

containers:
  main:
    image: linkstackorg/linkstack:latest # use a fixed version tag in real apps
    ingress_port: 80
    mounts:
      data:
        data: /htdocs

This is enough for a working app:

  • version: 1 is the version of the app.yml format. It is currently always 1.
  • containers lists the app's containers by name. A container named main with an ingress_port receives the app's web traffic: when the user adds a domain to the app, requests to that domain are forwarded to port 80 of this container.
  • mounts.data mounts volume data at /htdocs. Volumes must be declared in metadata.yml.

Every container that receives traffic gets a Kubernetes Service with the same name as the container, so other containers of the app can reach it by name (here: http://main).

Containers ​

Each entry under containers is a long-running container (a Deployment by default), a cron job or a job, depending on its fields.

Common fields ​

FieldTypeDescription
imagestringContainer image. Required.
command, entrypointstring or string[]Override the image's command and entrypoint. A string is split like a shell would (quotes are respected).
environmentmapEnvironment variables. Values are strings, numbers or booleans, or { secret: <name>, key: <key> } to read the value from one of the app's secrets.
userstringuid or uid:gid to run as.
working_dirstringWorking directory.
stop_grace_periodstringTime to wait for the container to stop.
restartstringRestart policy.
shm_sizestring or numberSize of /dev/shm.
fs_groupnumberGroup that owns mounted volumes.
read_only_rootfsboolMount the container's root filesystem read-only.
mountsmapVolumes to mount, see Mounts.
has_permissionsstring[]Permissions only this container needs, see permissions.
network_policyobjectNetwork policy for this container, see Network policies.
service_accountobjectKubernetes API access for this container (RBAC rules). Anything beyond read-only access in the app's own namespace requires admin permissions.
cap_add, cap_dropstring[]Linux capabilities. Adding any capability other than CAP_NET_RAW requires admin permissions.
privileged, host_networkboolRun privileged or in the host's network namespace. Both require extra permissions.

Long-running containers ​

These fields are only available for long-running containers:

FieldTypeDescription
typeDeployment or StatefulSetKubernetes workload type. Default: Deployment.
ingress_portnumberPort that receives HTTPS traffic from the app's domains.
http_ingress_portnumberPort that receives plain HTTP traffic, as a fallback.
path_prefixstringServe this container under a path of the app's domain (for example /api). The main container can't have a path prefix.
strip_prefixboolRemove path_prefix before forwarding a request. Default: true.
enable_http_compressionboolLet the ingress compress HTTP responses. Default: true.
auth_excludeboolDon't require login for this container when the user protects the app.
internal_portsmapPorts other containers and permitted apps can reach.
public_portsmapPorts exposed directly on the server, through a LoadBalancer service named <container>-public. Requires the builtin/network/public-port permission.
use_https_with_hostname, tls_insecurestring, boolTalk to the container over HTTPS (with this SNI host name) and optionally skip certificate verification.
pluginsmapPlugins this container implements, see plugins.
middlewaresmapHTTP middlewares, currently only type: Headers.

Port maps have the form <service port>: <container port>. A bare port is TCP; use tcp: and udp: keys for explicit protocols:

yaml
internal_ports:
  8080: 80
  udp:
    5353: 53

Jobs and cron jobs ​

A container with schedule (a cron expression) becomes a CronJob. A container with job_type becomes a Job: OneTime runs once after installation, OnUpdate runs on every app update.

yaml
containers:
  migrate:
    image: linkstackorg/linkstack:latest
    job_type: OnUpdate
    command: php artisan migrate --force
  cleanup:
    image: alpine:3
    schedule: "0 3 * * *"
    command: ["sh", "-c", "rm -rf /data/tmp/*"]
    mounts:
      data:
        data: /data

Mounts ​

yaml
mounts:
  data:
    data: /htdocs           # volume "data" at /htdocs
    data/config: /config    # sub-path "config" of volume "data"
  secrets:
    credentials: /run/secrets/credentials
  tmp:
    cache: /tmp/cache       # an empty directory that lives as long as the pod
  host_paths:
    /dev/dri: /dev/dri      # requires admin permissions
KeyDescription
dataPersistent volumes declared in metadata.yml, as <volume>[/<sub-path>]: <mount path>.
secretsOne of the app's secrets, mounted as files.
tmpTemporary empty directories.
host_pathsDirectories of the host. Using them requires the builtin/root permission.

Services ​

Services are created automatically for containers with an ingress_port, internal_ports or plugins. Declare a service under services only if you need more control:

yaml
services:
  web:
    type: ClusterIp           # or LoadBalancer
    target_container: main
    ports:
      80: 8080

Ingress to other apps ​

The top-level ingress list routes traffic of the app's domains to services of other apps, or adds more routes:

yaml
ingress:
  - target_app: other-app
    target_svc: api
    port: 3000
    path_prefix: /api

The app needs a permission of other-app that covers this service and port, see sharing data. Only one route without path_prefix (the primary route) is allowed.

Secrets ​

yaml
secrets:
  credentials:
    string_data:
      password: "{{ derive_entropy(identifier='db-password') }}"
    data:
      key.bin: aGVsbG8=        # base64-encoded

Generate passwords with derive_entropy in an app.yml.jinja template. The values stay the same across reinstalls and updates.

Network policies ​

By default, every container of an app can reach the internet, DNS and the other containers of the same app, and can only be reached from inside the app (and through its ingress). You can change this with a top-level network_policy or one per container:

yaml
network_policy:
  egress:
    allow_world: false
    fqdns:
      - match_name: api.example.com
        allowed_ports: [443]

Set disable_default_network_policy: true to skip the default policy. This applies a default-deny policy, so the app can hardly use the network at all.

Plugin resources ​

Top-level keys other than the ones above are resources for custom resource plugins, in the form <plugin app>: <plugin id>: <definition>. See custom Kubernetes objects.

Free and open-source software under the GNU AGPL 3.0 or later.