Deployment¶
Configuration¶
Every role reads the same configuration: one TOML file (--config, else
SCHEDR_CONFIG_FILE, else /etc/schedr/config.toml) and environment variables mirroring
it, e.g. SCHEDR_CONFIG__MASTER__GRPC_PORT for [master] grpc_port. Flags win over the
environment, which wins over the file. Unknown keys are an error. Each role uses only its own
sections. The configuration reference lists
every key. Workers find DAG roots through SCHEDR_DAG_PATH and script roots through
SCHEDR_SCRIPT_PATH; see Plain scripts. schedr standalone
also takes them as options, --dag-path PATH and --script-path PATH, each repeated for more:
given, an option’s list replaces the variable’s and the file’s. A relative path is taken from
the folder it starts in, so --dag-path . is that folder, a root named after it.
The roles in a cluster¶
Role |
Replicas |
Needs |
|---|---|---|
|
one leads; a second waits as a standby (Failover) |
|
|
one or more |
|
|
as many as the load needs |
|
|
one |
|
Postgres is the database for anything spread over several hosts. Migrate the schema with
schedr db migratebefore starting the master (it holds the master’s lease while it migrates, so it is refused while a master runs;--waitwaits for the lease instead), or start the master withschedr master --migrate, which migrates a schema that isn’t up to date once it holds the lease. Either way,[database] change_notificationsis applied once the lease is held, including when the schema is already up to date (see Live updates). Without either, the master refuses such a schema. The webserver waits for a schema it can use (/readyznot ready, checked every 5 s), so it can start before the migration. SQLite works for roles on one host with a local disk.Upgrade the master first, then the webservers and workers (see Parsing and code versions).
Workers’
terminationGracePeriodSecondsshould match[worker] termination_grace_period, so a draining worker has the time it expects.Probes go to the ops port: liveness on
/healthzfor every role, readiness on/readyzfor the master, the webserver andschedr ui(ready once it listens). Workers need no readiness probe: nothing connects to them through a Service. A standby or paused master is not ready (503), so the master Service directs workers to the leader. A stream reaching a non-leading master is refused withUNAVAILABLEand the worker reconnects.Connection files: commands write these under
/dev/shmby default. Docker and Podman typically give a container 64 MB there; size it for concurrent attempts and their connection files. In Kubernetes, mount anemptyDirwithmedium: Memoryat/dev/shmor at a base chosen by[worker] connection_dir, and size it and the pod’s memory for those files. The worker checks ownership and permissions on the path at startup; see Commands’ connection files.Memory: a worker pod’s memory limit is split between its slots (see Workers); size the pod for its slots. The chart turns the fork server on by default, and with its preload list the worker keeps two long-lived fork server processes, so size the pod for them too (see Workers and below).
The chart’s mode: distributed¶
charts/schedr/ with mode: distributed runs this layout. The shared settings mean the same as
in standalone (database, serviceAccount, istio, vault, dags.files, gitSync,
passEnv, config, env), and the API’s Service keeps its name, so moving from standalone
is one helm upgrade with mode: distributed on the same Postgres: the history stays,
standalone’s pod goes, the roles come (a short downtime). Standalone’s volume stays behind
(NOTES say how to delete it). Distributed needs Postgres: SQLite is refused.
Role |
Kubernetes |
Image |
Notes |
|---|---|---|---|
master |
a Deployment, 1 replica, |
|
The old master stops (giving up the lease) before the new one starts. |
webserver |
a Deployment, |
|
The API’s Service |
workers |
a StatefulSet, |
|
A headless Service |
ui |
a Deployment, |
|
The web UI over the release’s own webserver ( |
Each role has its own section (master, webserver, worker, ui: replicas, resources,
image for the server roles, serviceAccountName, podAnnotations, nodeSelector,
tolerations, affinity); standalone keeps the top-level ones. The top-level config and
env reach every role, the UI’s too. The objects are named after the release
(<release>-schedr, or the release’s name when it holds schedr), and Kubernetes allows 63
characters: the chart refuses a full name over 45 characters in this mode (52 in standalone),
its longest object’s name being that and -webserver-ui-port.
The fork server. worker.forkServer turns it on for these workers and for standalone’s
own worker, not for the master or the webserver. It is on by default.
enabledis true.pathis the image’s Python,/usr/local/bin/python3. An image builtFROMthis one keeps that path; setpathwhen the interpreter is somewhere else.preloadis the modules the preloaded server imports. The default is the image’s libraries exceptpolars, kept inimages/schedr/preload.txt(the image, below). Set it to add libraries an image of your own brings in. Leave out one that starts a thread: the preloaded server is then disabled, and the worker warns (see Workers).
The image’s build imports that list and fails if a thread is still running. make chart-check fails if this default differs from the file.
The chart sets that interpreter’s path, fork_server and preload. The interpreter is
config.DAGS__INTERPRETER, or python when that is unset; the chart uppercases the name. It
names the interpreter in environment variables, so the chart refuses a name with other than
letters, digits and _; dagsRoot too, for the same reason.
A renamed DAG interpreter is the one it sets. To use an interpreter of your own in
config, turn worker.forkServer.enabled off. The chart refuses to render when both set
the DAG interpreter (config.INTERPRETERS__PYTHON, or INTERPRETERS__PYTHON__PATH and
the rest of that table; the same keys with the interpreter’s name in upper case). With the
fork server off, set path, fork_server and preload in config. Or leave the
interpreter out of config and use worker.forkServer.path.
With the default list the worker keeps two long-lived processes, the preloaded server and the bare one. Size the pod for them as well as its slots.
TLS between the roles: tls.mode: app (the default) is schedr’s own mTLS, with a
certificate per role in a Secret of its own (ca.crt, tls.crt, tls.key), from, in order:
tls.existingSecrets(master,webserver,worker, anduiwhile the UI is deployed, as it is by default: one each): the master’s certificate must name its Service (<release>-master.<namespace>.svc), the workers’ must nametls.workerName(schedr-worker), the UI’stls.uiName(schedr-ui), and the webserver certificate must name its Service (<release>.<namespace>.svc). Each needs serverAuth and clientAuth;cert-manager:
tls.certManager.issuerRefcreates aCertificateper role;generated by the chart (
tls.generate, on by default): a CA and a certificate per role at install, valid 10 years, kept on upgrades (made again when the names they must carry change, includingtls.workerName,tls.uiNameandclusterDomain). Helm reads them back from the cluster, whichhelm template, client dry runs and GitOps tools that render (ArgoCD) can’t: they would make new ones on every render, so use cert-manager or your own Secrets there. To rotate, delete the<release>-*-tlsSecrets and upgrade; schedr reloads the files without a restart.
tls.mode: mesh sends plain traffic for a service mesh to encrypt (Istio) and needs no
certificates.
Accounts and Istio: created without a serviceAccount.name, the ServiceAccounts are one per
role (<release>-master, -webserver, -worker, and -ui when enabled). With a name,
every role shares that account, as standalone did. This keeps any Vault role or policy
bound to the account when moving to distributed mode;
serviceAccount.create: false runs every role as one existing account (a role’s
serviceAccountName overrides each of these). The Vault Secrets Operator authenticates as
vault.auth.serviceAccount, by default the pods’ account (the master’s when each role has its
own). In tls.mode: app the master’s gRPC port and the workers’ log port are named tls-grpc
and tls-logs, so Istio’s sidecars pass schedr’s own TLS through instead of parsing it. The
workers’ addresses use clusterDomain (cluster.local).
The istio.authorizationPolicy adds a policy per role listing every port it serves: the
master’s gRPC port for the workers, the workers’ log endpoint for the webserver, by account
when each role has its own, else by namespace (and sameNamespace lets the whole namespace
in, as in standalone). With istio.enabled the chart also adds a DestinationRule
(ISTIO_MUTUAL) for the workers’ headless Service: Istio sends calls to a headless Service’s
pods without its automatic mTLS, so without it the webserver’s log requests would carry no
identity and every policy would refuse them.
Tasks’ environment: tasks get a clean environment, so a variable of the workers’ (a
MongoDB URI from a Secret, a proxy) reaches them only when listed in passEnv:
env:
- name: MONGO_URI
valueFrom: {secretKeyRef: {name: mongo, key: uri}}
passEnv: [MONGO_URI]
scripts/kind-distributed.sh checks it on a local kind cluster: standalone on Postgres with a
run, then mode: distributed (the run still there), two workers over mTLS with generated
certificates, a DAG run, a task’s log read through the webserver from its worker, the
certificates kept by an upgrade, and a worker deleted while its task runs (the task finishes
in the drain, one attempt). MESH=1 does the same on the mesh cluster of kind-mesh.sh, in
tls.mode: mesh, with the internal links allowed by account only. Killing the master or a
worker without a drain is a separate check, below.
One pod: schedr standalone, the production start¶
Production starts with standalone in one pod: first on SQLite, then on Postgres, and the separate roles only if the load needs them (a full switch: the history stays in Postgres).
The images. Each release pushes three, for x86_64, each in two kinds (decision 454): on
glibc (Debian, python:3.14.8-slim) from its manylinux wheel, the plain tag, and on Alpine
from its musllinux wheel, the tag with -alpine (1.1.0-alpine):
ghcr.io/ptutak/schedr (this section’s base image, for standalone and workers),
ghcr.io/ptutak/schedr-slim (Python and the package only, without the base image’s task
libraries and connection clients: for tasks that need none of them, or an image of your own
with just what they use; make image-slim) and ghcr.io/ptutak/schedr-server (the binary
alone, for the master, the webserver and schedr ui; below). make image, make image-slim
and make server-image build the glibc ones; make image-alpine, make image-slim-alpine
and make server-image-alpine the Alpine ones. In 0.1.0 the plain tag was Alpine’s.
Their tags are the version (1.1.0) and its series (1.1), and the same with -alpine
(1.1.0-alpine, 1.1-alpine); a release candidate has only its own (1.1.0rc1). There is
no latest: a new version migrates the database (schedr db migrate), which a moving tag
would start unasked. The chart uses them by
default, tagged with its appVersion (image, and master.image, webserver.image and
ui.image for the server roles).
The image. images/schedr/Dockerfile builds the base image (make image; on Alpine,
Dockerfile.alpine): Python 3.14 and the schedr package, tini as PID 1, a data directory writable by group 0
for OpenShift’s arbitrary UID, and libraries for tasks (about 410 MB in all, polars the
largest):
For |
Libraries |
|---|---|
API calls |
|
Data |
|
Networking |
|
MongoDB |
|
They are listed in images/schedr/requirements.in and pinned with their dependencies in
requirements.txt (make image-requirements, no version newer than two weeks). The
preloaded fork server imports them except polars, by module name, from
images/schedr/preload.txt: yaml for PyYAML, dateutil for python-dateutil, dns for
dnspython, and the others under the names in the table. polars starts threads on import,
so preloading it would disable that server. The image’s build imports the list and fails if
a thread is still running. Async task functions use the event loop available in their Python
environment; installing uvloop selects it automatically
(the event loop). Your DAGs’ libraries go in an
image of your own built FROM it:
examples/kubernetes/Dockerfile does it in two stages, compiling in a builder stage what has
no wheel, so no compiler ends up in your image (on the glibc base nearly every library has
one; on -alpine, the builder takes its packages from apk and looks for musl wheels).
The chart. charts/schedr/ with mode: standalone:
one replica (a StatefulSet) with a ReadWriteOnce volume on block storage for the data directory (task logs, the worker’s journal, and on SQLite the database);
the database, one of three: SQLite on the volume (nothing set: the start);
database.postgres, the host, port, database name and URL parameters in values and the user and password from a Secret (existingSecret, keysuserKey/passwordKey), put into the URL by Kubernetes ($(SCHEDR_DB_USER)), so they must not contain@ : / ? # %or a space; ordatabase.existingSecret, a Secret holding the whole URL. Any connection pooler can sit in between. Behind one in transaction mode the master finds it and polls for new commands, and the webserver can’t follow changes for the UI, so the live pages refresh on the refresh interval (15 s by default; see the master). To listen anyway,database.notificationsUrlKeynames a key of the same Secret with a URL straight to Postgres. The master and the webserver both use it (database.postgres.notificationsHostwithdatabase.postgres);what the database user needs: its own database only. It owns the database (so it can create the schema in
public, which Postgres 15 no longer lets everyone do), and can use PL/pgSQL (DOblocks: a master’s lease check), which Postgres allows everyone by default; a server that revokes it refuses a master’s writes;migration, how the schema is migrated (both hold the master’s lease). When the schema is already up to date they leave it, and they still apply[database] change_notificationswhen the triggers differ from the setting (see Live updates):initContainer(the default): an init container runsschedr db migrate --waitbefore schedr starts, so a failed migration shows as a failed init container, and the master (standalone’s included) refuses a schema that isn’t up to date;onStart: schedr migrates at start (--migrate). Use it under Istio with classic sidecars: an init container runs before the pod’s proxy exists, so it can’t reach the database through the mesh. Native sidecars (Kubernetes 1.29 on, Istio’sENABLE_NATIVE_SIDECARS) start before init containers and don’t have this problem;
vault: Secrets kept in sync from Vault by the Vault Secrets Operator, e.g. the onedatabase.postgres.existingSecretnames: a VaultAuth (auth.role,mount, the Vaultnamespace) for the pod’s ServiceAccount, and a VaultStaticSecret perstaticSecretsitem (each key of the Vault entry a key of the Secret). A change in Vault restarts schedr (restartOnChange, after a drain), since it reads its Secrets at start. Off by default: create the Secrets by hand;serviceAccount: the chart creates one by default, holding no permissions;create: falsewith anameruns the pod as an existing one (e.g. the account a namespace in the mesh already has). Its token isn’t mounted (automountToken: false): schedr never calls the Kubernetes API. With a Vault secret storage on, a projected token of its own is mounted for Vault’s login only (Secret storage);the pod’s
fsGroupis 0, so the volume is writable by the image’s group, except on OpenShift (found by its API), which sets its own;terminationGracePeriodSeconds(600) is passed to schedr as[worker] termination_grace_period, so a drain always fits the pod’s grace period;probes on the ops port, a Service with ports named for Istio (
http-api,http-ops), an optionalServiceMonitor;the fork server on this pod’s own worker, the same
worker.forkServeras the distributed workers (on by default);more settings as
config(WORKER__SLOTS: "4"becomesSCHEDR_CONFIG__WORKER__SLOTS).
The DAGs reach the pod in three ways: dags.files is a root of its own, beside
dagsPath’s, which holds either git-sync’s checkout or the image’s DAGs (git-sync’s volume
covers the image’s folder), so at most two roots:
Way |
Values |
A change reaches schedr |
For |
|---|---|---|---|
A flat folder through |
|
within about a minute, without a restart |
trying DAGs, a handful of files (up to 512 KiB together) |
git-sync |
|
within |
the real way: a repository with history and review |
Baked into the image |
|
with a new image (a restart, which drains) |
DAGs that change with their libraries |
From a folder: the script takes the folder’s
*.pyfiles and its.schedrignore(hidden files,__pycache__and hidden folders left out) and prints values with each file’s content in base64 (no file can break the YAML; the same folder always gives the same values). The folder must be flat: Python files in a subfolder are refused, since a ConfigMap’s files can be put in subfolders only by the pod’s spec, which would restart schedr whenever a file is added; helpers are top-level modules (import helpers), and packages go through git-sync. It needs only bash and coreutils, so it runs in any CI job with Helm; it checks everything before printing anything:charts/schedr/dags-values.sh dags/ > dags-values.yaml helm upgrade --install schedr charts/schedr -f my-values.yaml -f dags-values.yaml
The chart makes a ConfigMap of them, mounted at
/dag-filesas the rootfiles. The root is the ConfigMap’s..datalink, which the kubelet switches to each new version, as git-sync switches its link. The first upgrade with files adds a volume to the pod (a restart); adding, changing or removing files later only changes the ConfigMap.git-sync keeps a repository in
dagsPath(rootdagsRoot,dags). Credentials come from a Secret,gitSync.credentials:type: tokenfor an HTTPS repository (a user and a token, e.g. a GitLab deploy token, keysusernameandpassword),type: sshfor an SSH one (keysssh-privatekeyandknown_hosts, the linessh-keyscan <host>prints). Under Istio withREGISTRY_ONLY, a repository outside the mesh needs a ServiceEntry (istio.serviceEntries: the host on 443, or 22).dagsPath: ""leaves out the image’s root, for a deployment whose DAGs come only fromdags.files.
Switching from SQLite to Postgres takes one helm upgrade with database.postgres
(or database.existingSecret) set. This does not copy the history to Postgres. The pod
drains and restarts on the new database, migrates it as migration says, and parses the
DAGs again. The volume keeps the task logs, journal and SQLite file with the old history.
Clearing those values switches back to SQLite.
database:
postgres:
host: postgres.schedr.svc
name: schedr
params: sslmode=require
existingSecret: schedr-pg # keys username and password
Anything else built from a Secret goes in env, whose values may refer to earlier variables
as $(NAME), and any configuration key in config.
What to know:
One master per database: a second pod during a rollout waits as a standby (see The master); on SQLite the volume lets only one pod in anyway. If the master part fails (another took its lease over), the whole pod’s process exits and Kubernetes restarts it.
Memory: the pod’s limit is shared by tasks, schedr itself and, with the chart’s default, the two long-lived fork server processes. Task budgets are (limit − 25 %) ÷ slots in standalone (
[worker] memory_reserveto change it). schedr’s own process used about 20–25 MiB in measurements. Size the pod for those two processes as well as the slots.Upgrades restart every role at once: running tasks get the grace period, then are interrupted and run again.
Who may reach the REST API and the web UI is set by
[webserver.auth](none, a sign-in proxy’s header, or Basic against a users file; see Sign-in); with none, keep the Service internal or put it behind the mesh (below). On this pod the UI is on the API’s port, so that Service is the UI too.The web UI is at
/on the API’s port. Its deployment is nameddefault./docsserves the image’s documentation. What the pages show is The web UI.scripts/kind-standalone.shinstalls the chart on a local kind cluster on SQLite, switches it to Postgres withdatabase.postgres, then to a URL Secret, then adds DAGs from a folder (a second upgrade without a restart) and from git-sync (a git server in the cluster), and runs a DAG each time.
Inside an Istio mesh¶
In a namespace that is part of the mesh, nothing reaches schedr or leaves it without Istio’s
objects. The chart’s istio values create them, each optional and off by default:
Value |
Creates |
For |
|---|---|---|
|
the sidecar label and annotation, and the proxy’s settings |
schedr starts once its proxy is ready (it reaches the database through it), and the proxy stays until schedr’s connections close. Without that, the proxy stops 5 s after SIGTERM and a drain’s results never reach the database |
|
a VirtualService on an existing Gateway ( |
the API from outside the namespace. On a standalone pod that is the web UI too, on the same port. A |
|
a RequestAuthentication ( |
tokens (JWT, e.g. Keycloak’s) checked at schedr’s pod. It refuses only invalid tokens: a request without one passes, unless the policy below requires one |
|
an ALLOW AuthorizationPolicy for schedr’s pod |
who may call it: anything from the same namespace ( |
|
a STRICT PeerAuthentication |
mTLS required, for a namespace that doesn’t already require it |
|
ServiceEntries (a name and a spec each) |
destinations outside the mesh under |
An ALLOW policy denies whatever it doesn’t list, so the chart’s policy lists every port schedr serves; adding a policy of your own for the API alone would cut off the ops port.
The kubelet’s probes pass whatever the policy says: Istio sends them from inside the pod.
The objects use Istio’s
v1API where the cluster serves it (Istio 1.22 on), elsev1beta1(older Istio, OpenShift Service Mesh 2).From outside, the CLI passes the prefix and the token:
schedr dags list --server https://<host>/service/schedr --token "$TOKEN". Swagger UI is athttps://<host>/service/schedr/api/v1/docs/; paste a token into its Authorize button to call the API from it. Its page refers to the description by a relative URL, and the description names the prefix fromX-Forwarded-Prefixas its server, so its calls go through the same prefix.With an existing ServiceAccount shared by other workloads, a policy can tell schedr’s callers apart only by namespace or token, since Istio identifies a caller by its account.
scripts/kind-mesh.sh installs all of this on a local kind cluster with Istio
(REGISTRY_ONLY; SIDECARS=native or classic) and checks it: Swagger UI opens without a
token, the API is refused without one, with a forged one and without the required group, the
CLI through the gateway with
--token, a DAG run on Postgres migrated on start, and a pod stopped while a task runs, whose
result still reaches the database through the sidecar. Like the other kind scripts, it refuses a
context whose server isn’t loopback, before calling anything on that cluster.
Signing in through Keycloak¶
Istio checks tokens, but a browser can’t get one by itself: opening the web UI to everyone, or
adding basic sign-in beside Keycloak, would let people around the stronger sign-in. A login
proxy closes that gap with namespace objects only, no mesh-wide configuration:
examples/kubernetes/oauth2-proxy.yaml holds an oauth2-proxy
Deployment, its Service, a VirtualService and an AuthorizationPolicy, and the chart’s values
that go with them.
browser ─► ingress gateway ─► oauth2-proxy ─► schedr ui (its sidecar checks the token)
└─ /api/ ─────────────────► schedr webserver (the CLI's own token)
One sign-in for the API and the UI. oauth2-proxy signs the person in with Keycloak and passes their ID token on as
Authorization: Bearer. The chart’srequestAuthenticationchecks it at the UI’s pod as it does at the API’s,authorizationPolicy.api.claims(e.g.groups: [schedr-users]) decides who gets in, andoutputClaimToHeaderscopiespreferred_usernameintox-forwarded-user, the name schedr records (webserver.authmodenonewith thatidentityHeader).The pod doesn’t trust the proxy. Someone who reaches the UI’s pod around it still needs a valid token with the group: set
authorizationPolicy.sameNamespace: false, so nothing in the namespace passes without one.LDAP comes through Keycloak: its user federation signs LDAP users in, and a group mapper puts their groups in the token (with “Add to ID token” on: the proxy passes the ID token). schedr itself reads no LDAP.
Refresh the token before it expires. schedr’s pages keep an event stream open and reload every minute, and an expired token is refused at the pod: the page stops updating. The proxy’s
--cookie-refreshmust be shorter than the realm’s access token lifespan (Keycloak’s default, 5 minutes:4m).Who can do what: schedr has no roles (see Sign-in), so the group claim decides who reaches a deployment, and everyone who does can do everything there. For finer control, separate deployments behind one UI (
ui.deployments), each with its own policy.From Keycloak you need one confidential client, its redirect URI
https://<host>/oauth2/callback, and the group mapper. UnderoutboundTrafficPolicy: REGISTRY_ONLY, the proxy reaches Keycloak through a ServiceEntry (istio.serviceEntries).
The same works with another proxy that passes a Keycloak token on, gogatekeeper for one. A proxy
that only names the person in a header (OpenShift’s oauth-proxy) needs proxy_header mode
with allowRemote, and a policy that lets only the proxy reach the UI’s pod: anyone else
reaching it could name any user.
Recent Istio (1.31, for one) injects native sidecars: the proxy starts before init
containers and stops after schedr, so neither the migration nor a drain needs anything there.
The chart’s settings are for classic sidecars (older Istio, OpenShift Service Mesh 2), and
harmless otherwise. Which your cluster runs shows in the pod: istio-proxy among the init
containers is native, among the containers classic.
On a laptop¶
On a laptop, schedr standalone --migrate runs everything on localhost, with SQLite in the
data directory ([worker] data_dir, else ~/.local/share/schedr), migrating the database at
start and applying [database] change_notifications once it holds the lease.
In this repository, make standalone does the same for trying things by hand (development
only): the debug binary just built, the Python environment of uv sync for DAG files and
tasks, and everything in .schedr/ in the repository (git-ignored): the SQLite database
(.schedr/schedr.db, to open in an IDE), task logs and the journal. It runs the DAGs in
examples/ unless DAGS=<directory> says otherwise. examples/.schedrignore leaves out
test_*.py and conftest.py: the examples’ own tests, not DAG files. The API and the web UI are on
0.0.0.0:8080 (LISTEN, all addresses by default, so it can be reached from outside WSL:
the UI at http://<address>:8080/, Swagger UI at http://<address>:8080/api/v1/docs/;
schedr dags list needs no --server with 0.0.0.0 or 127.0.0.1) and the ops port on
8090. After make docs, the next make standalone points [ui] docs_dir at site,
so the UI serves the documentation at /docs. Python tasks fork from a fork
server, as in the chart’s pods (see The fork server);
FORK_SERVER=false spawns them, as the configuration’s default does. It signs no one in
(auth mode none): on a network you don’t trust, run make standalone LISTEN=127.0.0.1.
Ctrl-C stops it, after cutting the pages’ open event streams about 3 seconds after the stop;
make standalone-clean starts afresh. A worker’s code copies are read-only, so a task can’t
change the code it runs; to delete a worker’s data_dir by hand, make it writable first
(chmod -R u+w <data_dir> && rm -r <data_dir>).
make standalone-separate-ui runs a small federation, to see one UI over several
deployments of both kinds. main runs as separate roles on the DAGs of DAGS, and second
as a standalone with --no-ui on those of DAGS2 (examples/docs by default). A folder’s
subfolders are scanned too, so main, on examples/, has the DAGs under examples/docs as
well. A schedr ui in a process of its own serves both, at http://<address>:8082/.
main is four schedr processes on one SQLite file, the links plain ([tls] mode = "mesh")
as they are on this machine: a master, a standby master started once the API answers, a
webserver and a worker. The worker reaches the masters through
scripts/master_proxy.py, a stand-in for the chart’s master Service: each new connection
goes to whichever master’s /readyz answers. Kill the leading master and the standby takes
over within the master lease period (30 s), the worker
reconnects to it through the proxy, and runs go on. A worker has no database, so main’s
tasks can’t read the db secret storage: the examples that read a secret fail there and
run on second.
second also has a root named broken, written to .schedr/federation/broken/. It holds
two DAG files that fail to import on purpose: one imports a module that is not installed,
and one raises an error that names an address with its password. second’s worker shows a
warning, and the Import errors page lists the two files, with the password masked. The
Deployments page shows the UI in a process of its own, main’s four processes with its
leader and standby, and second as one process holding its webserver, master and worker.
|
Port |
Ops port |
|---|---|---|
the masters’ address for the worker (the proxy) |
8070 |
|
the first master (gRPC) |
8072 |
8090 |
the standby (gRPC) |
8071 |
8091 |
the webserver (the API) |
8080 |
8093 |
the worker (its log endpoint) |
8081 |
8094 |
second has its API on 8180, gRPC on 8170, its log endpoint on 8181 and ops on 8190. The
UI’s ops port is 8092. PORT_OFFSET is added to every one of these ports, so
PORT_OFFSET=10000 runs this next to a make standalone. Each deployment keeps its data in
.schedr/federation/<name>/, and the UI’s configuration is written to
.schedr/federation/ui.toml. Ctrl-C stops them all; one process ending (a master killed to
see the takeover) leaves the others running.
Running schedr ui¶
schedr ui is the web UI as its own process, over one or more webservers. It needs no
database and no DAG code. The server image is enough: it has the binary and the
documentation, and this role runs no user code. The base image has them too. The chart’s
distributed mode deploys this process (ui.enabled, on by default), and its mode: ui deploys
it alone over other deployments; elsewhere, run it yourself. Standalone
already serves the same pages on its API port, and ignores [ui] bind, [ui] port and
[ui] deployments.
Point each deployment at that deployment’s webserver. A name is letters, digits, - and
_, shown on the pages and used in their addresses, and each name once. With no list, or a
name that breaks those rules, schedr ui refuses to start and says what to fix.
[ui]
bind = "0.0.0.0"
port = 8082
[[ui.deployments]]
name = "etl"
url = "http://schedr-webserver.etl.svc:8080"
[[ui.deployments]]
name = "ml"
url = "http://schedr-webserver.ml.svc:8080"
It listens on [ui] port (8082), on all interfaces unless [ui] bind says otherwise.
Set [ui.auth] to choose how people sign in: none, proxy_header or basic
(see Sign-in). With none, it warns when it listens beyond
localhost.
For each deployment, use https:// to reach the webserver’s [webserver] ui_port over
mTLS, with the UI’s certificate configured in [tls]. Without mTLS, set token_file
to a file holding that webserver’s [webserver] ui_token_file token. This lets the UI
pass the signed-in person’s name to the webserver. The HTTP examples above send no
credentials; they suit APIs that allow callers without a token. The chart configures
this link for its own deployment.
Probes go to the ops port, as for the webserver: it is ready once it listens. /docs
serves the image’s documentation when [ui] docs_dir points there. What the pages show, the themes and the times are The web UI.
Failover¶
Only one master leads at a time (see The master). What happens when it goes away depends on the mode.
Standalone fails over by restarting. Its worker reaches only its own process’s master, on localhost. Restarted after a clean stop, it leads again at once; after a crash it waits up to the master lease period (30 s). In Kubernetes, the pod’s restart is the failover.
A standby master beside a standalone doesn’t help. A
schedr masteron the same database takes over the lease when the standalone crashes, but it has no worker and no API, so the runs it creates wait. The restarted standalone then waits as a standby, and its own master refuses its worker (“not leading”), so nothing runs until the other master stops.Distributed mode on Postgres fails over without stopping the tasks. Workers run them on, reconnect, and send their results to whichever master leads next. The chart runs one master pod (
strategy: Recreate), so its failover is Kubernetes restarting that pod.A hot standby (two masters running at once) works outside the chart: start a second
schedr masteron the same database, and give the workers a[worker] master_urlthat reaches only the master whose/readyzanswers (a Service, or a load balancer with that health check). The standby takes over within the lease period after a crash, at once after a clean stop. Stress scenarios 4 and 5 test that takeover (Stress tests), andmake standalone-separate-uiruns one on this machine, a small proxy standing in for the Service (On a laptop). The chart’smaster.replicasis planned after 1.1.0 (M5.3a).
Killing the master or a worker¶
kubectl delete pod sends SIGTERM. The worker drains: a task that finishes within the grace
period ends success (one attempt), and one still running ends interrupted and runs again
without using a retry. scripts/kind-distributed.sh checks that with a worker deleted during
a 20 s task, and scripts/kind-mesh.sh checks it for standalone in the mesh.
A crash leaves no time to drain. kubectl delete pod POD --force --grace-period=0 kills the
container at once. What schedr does then is in State and failures. With the
chart’s defaults (one master, workers as a StatefulSet with a volume each, the master lease period of 30 s):
Killed |
The run |
Attempts |
|---|---|---|
The master pod |
Finishes. Workers keep the task and register again with the new master. It holds the lease within the master lease period (30 s) of the old one’s last renewal, after its pod has been scheduled and has started. The kind script allows 180 s for that. |
The same attempt, |
A worker pod |
Finishes when the task has a retry left. The default is |
|
The standalone pod, SQLite on its volume |
Finishes the same way. The volume keeps the database and the journal, so a run that already succeeded is still there. |
|
A worker listed lost after the master is killed means the downtime was counted against the
lease, which it must not be. A killed worker’s attempt is WorkerLost instead of
WorkerRestarted when its new pod is not ready within the worker lease (60 s). That
is the rule, and the kind script prints it. The other worker has to stay active.
scripts/kind-kill.sh runs these three, in that order, on the local kind cluster schedr-test
(context kind-schedr-test; any other cluster name is refused). It is not part of make check.
The context’s server has to be loopback; scripts/kind-standalone.sh,
scripts/kind-distributed.sh and scripts/kind-mesh.sh require the same, and all four
share scripts/kind-lib.sh.
It needs the images from make image and make server-image. hold sleeps 90 s with retries=0
(the master). again sleeps 30 s with retries=1 and retry_delay of 0 (a worker, then
standalone). The default delay is 5 minutes, which would only postpone the same retry. ping is
a short run that has to still be success after the standalone pod is killed.
On OpenShift, by hand¶
The same three checks, against a release that is already installed. Nothing in this repository
runs them: scripts/kind-kill.sh refuses every context except kind-schedr-test. A plain
kubectl delete pod is the drain above. The crash is the command with --force --grace-period=0.
Put these DAGs where the workers or the standalone pod read their code. ping is the
short run whose history should survive the standalone crash:
import time
from datetime import timedelta
from schedr import CommandOperator, Dag, task
with Dag("hold"):
@task(retries=0)
def hold() -> str:
time.sleep(90)
return "held"
hold()
with Dag("again"):
@task(retries=1, retry_delay=timedelta(0))
def again() -> str:
time.sleep(30)
return "again"
again()
with Dag("ping"):
CommandOperator("ping", command="echo pong")
The call inside with Dag records the task. Decorating the function and not calling it
leaves a DAG with no tasks: a trigger still returns a run, and that run never starts hold
or again. CommandOperator records ping by being constructed there.
CTX and NS are the lab’s context and namespace, REL the release name (schedr in the
kind scripts). Distributed, the CLI and the API are the webserver’s. Standalone, the pod is
schedr-0 and the same commands run there. The server image has no Python. Read the
attempts as JSON with wget and check them on the laptop.
CTX=<the lab context>
NS=<namespace>
REL=schedr
kubectl --context "$CTX" -n "$NS" exec "deploy/$REL-webserver" -c schedr -- \
schedr runs trigger hold --server http://127.0.0.1:8080
When hold’s attempt has started_at, kill the master. The attempts stay that one attempt,
and it ends success. schedr workers list shows both workers active again;
disconnected in between is the lease starting over.
kubectl --context "$CTX" -n "$NS" delete pod \
-l "app.kubernetes.io/instance=$REL,app.kubernetes.io/component=master" \
--force --grace-period=0
kubectl --context "$CTX" -n "$NS" exec "deploy/$REL-webserver" -c schedr -- \
wget -qO- "http://127.0.0.1:8080/api/v1/runs/<run id>/tasks/hold/attempts"
Then again. Kill the pod named by that attempt’s worker_id ($REL-worker-0 or
$REL-worker-1), not a fixed pod:
kubectl --context "$CTX" -n "$NS" exec "deploy/$REL-webserver" -c schedr -- \
schedr runs trigger again --server http://127.0.0.1:8080
kubectl --context "$CTX" -n "$NS" exec "deploy/$REL-webserver" -c schedr -- \
wget -qO- "http://127.0.0.1:8080/api/v1/runs/<run id>/tasks/again/attempts"
kubectl --context "$CTX" -n "$NS" delete pod "<worker_id>" --force --grace-period=0
The attempts, oldest first, are lost with WorkerRestarted, then success. WorkerLost
instead, when the new pod was not ready within 60 s, is the same rule.
Standalone on SQLite: ping first, then again. The commands run in $REL-0. The attempt’s
worker_id is that pod.
kubectl --context "$CTX" -n "$NS" exec "$REL-0" -c schedr -- \
schedr runs trigger ping --server http://127.0.0.1:8080
kubectl --context "$CTX" -n "$NS" exec "$REL-0" -c schedr -- \
schedr runs trigger again --server http://127.0.0.1:8080
kubectl --context "$CTX" -n "$NS" delete pod "<worker_id>" --force --grace-period=0
ping is still success. again is lost / WorkerRestarted, then success (WorkerLost
when the pod took longer than the 60 s lease).