Deployment¶
Network exposure¶
Before anything below: a Drakkar worker belongs on a trusted, private
network. It serves up to three HTTP ports — the API server and
the operator UI (api.port, default 8080), the optional webapp ingress
(sources.http.port, default 8090) and the optional Prometheus exporter
(metrics.port, default 9090) — and none of them is designed to face an
untrusted network. Bind them where only your own infrastructure can reach
them, and put a reverse proxy in front of anything that must travel
further.
Only /healthz and /readyz on the API port are meant to be reachable
without a token, because kubelet needs them.
See Security posture for what Drakkar’s own controls do and do not cover.
This page covers operational topics that apply when running Drakkar in a production environment: Kubernetes probes, rolling restarts, and the interaction between the API server and cluster health checks.
A shared folder plus a shared Postgres¶
This layout fits a deployment that already runs Postgres. The workers keep
their sealed history in a shared folder, as with the defaults. They find each
other, and choose the one worker that runs each slot of a cluster periodic
task (the archive pass included), through tables in Postgres instead of files in the folder. Both choices use
the same connections.postgres.main entry and so share one pool.
storage:
dir: /var/lib/drakkar
shared_dir: /mnt/drakkar-shared
connections:
postgres:
main:
schema: drakkar
manage_schema: true
pool_min: 1
pool_max: 4
autodiscover:
enabled: true
provider: postgres
connection: main
Set the connection string in the environment of every worker, for example from a Kubernetes Secret, not in the YAML file:
What to check:
- Every worker of the fleet uses the same autodiscover provider and database. Workers on different providers do not see each other’s cards or leases.
- Autodiscover needs
api.enabled: true. - The shared folder still holds the sealed recorder files and the archives. Only the cards and the leases of the cluster tasks move to Postgres.
manage_schema: truelets the first worker that starts create the schema and both tables. Workers that start together take turns through an advisory lock. Every worker repeats the idempotent DDL at its first provider start, also when the objects exist, so the role of every worker needsCREATEon the database (forCREATE SCHEMA IF NOT EXISTS) andCREATEon the schema (for the tables and the indexes). The role must also own the tablefleet_workers, because its twoCREATE INDEX IF NOT EXISTSstatements check ownership before they skip an index that exists. The simplest case is to let the worker role create the objects. For tables that another role created, setmanage_schema: false.task_locksneeds no ownership.- With an operator-managed schema, set
manage_schema: falseand run the command once, as a role that has the DDL rights:
The worker role then needs USAGE on the schema and SELECT, INSERT,
UPDATE and DELETE on fleet_workers and task_locks only. A worker
that finds a table missing fails the provider’s start with a message that
names this command and tries again at the next heartbeat (registry) or the
next slot of a cluster task (election).
For the recorder table of provider postgres, add --recorder and,
as needed, --table-prefix=<p> and --retention-hours=<n>; see
A worker with no disk and a central history.
- During a database outage the pipeline keeps running. The workers list
keeps its last snapshot, cluster task slots are skipped as
election_failed, an archive pass stops without publishing, and both
providers recover when the server is back. Watch drakkar_provider_breaker_open
and drakkar_provider_calls_total (see Observability).
More: Fleet registry: postgres, The election provider, Security: provider credentials.
A shared folder plus a shared Redis¶
This layout fits a deployment that already runs Redis. The workers keep their
sealed history in a shared folder, as with the defaults. They find each other,
and choose the one worker that runs each slot of a cluster periodic task
(the archive pass included), through keys in Redis instead of files in the folder. Both choices use the same
connections.redis.main entry and so share one client.
storage:
dir: /var/lib/drakkar
shared_dir: /mnt/drakkar-shared
connections:
redis:
main:
state_prefix: "drakkar:"
autodiscover:
enabled: true
provider: redis
connection: main
Set the URL in the environment of every worker, not in the YAML file. The database number is the path of the URL:
What to check:
- Every worker of the fleet uses the same autodiscover provider, and the same
server, database number and
state_prefix. Workers on different providers or different databases do not see each other’s cards or leases. - Autodiscover needs
api.enabled: true. - The shared folder still holds the sealed recorder files and the archives. Only the cards and the leases of the cluster tasks move to Redis.
- Use a database number of its own for the fleet, so that the keys of the
providers stay apart from other data. Use a Redis user of its own too, with
the rights
~drakkar:* +@read +@write +@scripting +@connection +time(the pattern followsstate_prefix) and thedefaultuser off where no other client needs it. These are category rights, so they allow more commands than the providers send, for exampleFLUSHDBandKEYS, and the key pattern does not limit those two. A Redis ACL does not limit databases either. ACL users need Redis 6.0 or later; on Redis 5.0, userequirepassand a database number of its own. A completeACL SETUSERline is in Security. - The server is Redis 5.0 or later, standalone or a primary behind a fixed
address. Redis Cluster is not supported. Use
rediss://in the URL for TLS. The client then verifies the certificate of the server against the system’s default certificate store and checks that the certificate names the host of the URL; this cannot be switched off. Put a private certificate authority into that store, or setSSL_CERT_FILEorSSL_CERT_DIR, which replace the default locations of the store. A URL with query options (?...) is refused when the provider starts, and so is a URL with a space, a control character or a non-ASCII character: remove a trailing newline from a URL read from a secret file. Write the special characters of a password as percent escapes (see the URL rules in Fleet registry). - A Redis server that restarts without its data loses the cards and the
leases, and so does a flush of the database. Eviction can delete them too:
every key of the providers has a time to live, so any
volatile-*and anyallkeys-*maxmemorypolicy can evict a live card or a lease. A database number of its own does not protect them, because the memory limit and eviction cover the whole server. The workers publish their cards again at the next heartbeat. An archive pass that held the lease finds it gone at its next refresh or check, stops without publishing, and the next slot takes the scope. That pass logsrecorder_archive_fencedwithreason=taken_over, whose detail says that another worker took the archive lock over, although no worker did: the provider can only answer that the pass no longer holds the lease. Under the default policy,noeviction, a full server evicts nothing and answers a script that needs more memory with an error that namesOOM. That error is final and counts as a failed operation for the breaker. - During a Redis outage the pipeline keeps running. The workers list keeps its
last snapshot, cluster task slots are skipped as
election_failed, an archive pass stops without publishing, and both providers recover when the server is back. Watchdrakkar_provider_breaker_openanddrakkar_provider_calls_total(see Observability).
More: Fleet registry: redis, The redis election provider, Security: provider credentials.
A shared folder plus Consul¶
This layout fits a deployment that already runs Consul. The workers keep their sealed history in a shared folder. They find each other through keys in Consul, and they choose the one worker that runs each slot of a cluster periodic task (the archive pass included) through a key held by a session.
storage:
dir: /var/lib/drakkar
shared_dir: /mnt/drakkar-shared
connections:
consul:
main:
address: http://127.0.0.1:8500 # the agent of the worker's host
state_prefix: drakkar
autodiscover:
enabled: true
provider: consul
connection: main
Set the token and the connection string in the environment of every worker, for example from a Kubernetes Secret, not in the YAML file:
What to check:
- Every worker of the fleet uses the same autodiscover provider, and the same
Consul cluster, datacenter and
state_prefix. Workers on different providers or stores do not see each other’s cards or leases. - Autodiscover needs
api.enabled: true. - The shared folder still holds the sealed recorder files and the archives. Only the cards and the leases of the cluster tasks move to Consul.
- The Consul token needs two rules, in which
drakkar/is thestate_prefix:key_prefix "drakkar/" { policy = "write" }andsession_prefix "" { policy = "write" }. The first allows every key under the prefix and the second every session of the datacenter, so give the fleet astate_prefixof its own and a token that nothing else uses. Withoutsession:writethe first publish fails with a403, not the start. See Security. - Consul decides liveness, not a worker’s clock: it ends the session of a
worker that stopped renewing (half of
autodiscover.offline_after, at least 10 seconds, and Consul ends a session at most twice that after the last renew). - Point each worker at a Consul agent that stays reachable and healthy,
usually the agent of its own host. When the cluster marks the agent’s node as
failed, Consul ends the sessions of that node, and the cards of its workers
leave the lists until the next heartbeat after the node is healthy. Use
https://in theaddressfor TLS (see Security for what it verifies). - During a Consul outage the pipeline keeps running. The workers list keeps its
last snapshot, and a worker that cannot reach Consul drops out of the lists
of the others once its session ends. It writes its card again when Consul is
back, without a restart. Cluster task slots are skipped as
election_failed, an archive pass stops without publishing, and the election recovers when the agent is back. Watchdrakkar_provider_breaker_openanddrakkar_provider_calls_total, which carry the labelfeature(registryorelection) for each provider (see Observability).
More: Fleet registry: consul, The consul election provider, Security: provider credentials.
A worker with no writable disk¶
A worker in a container with no writable disk leaves storage.dir empty and
turns the durable recorder off (recorder.enabled: false): the worker keeps
its recent events in the memory store only, and the UI pages
read them from there. The worker writes no recorder file, no cache file and no crash marker,
and it seals, publishes and archives nothing.
storage:
dir: ''
recorder:
enabled: false
connections:
redis:
main:
state_prefix: "drakkar:"
autodiscover:
enabled: true
provider: redis
connection: main
Points to check:
- The
filesystemregistry and election need a folder. With nostorage.dirand nostorage.shared_dir, use a service provider as above. Thefilesystemregistry then stays off, and the workers list shows only the current worker. Afilesystemelection with no folder stops the start of a worker that declares a cluster task. - With a
storage.shared_dirmounted, the worker still reads the sealed history of its cluster, but it publishes nothing into it. - Plan RAM for the memory store: up to about 600 MiB per worker with the default 256 MiB budget. See RAM to plan.
- A memory snapshot download holds one more copy of the store in RAM while it runs, because there is no folder for a temporary file.
- An enabled recorder with provider
sqliteand an emptystorage.dirfails the load; setrecorder.enabled: false, or use providerpostgres.
A worker with no disk and a central history¶
A worker with no writable disk can still keep a long history: set
recorder.provider: postgres. Every worker then writes its events to
one table in Postgres, and the trace with history reads the rows of its
cluster from there. No storage.dir and no storage.shared_dir are needed.
storage:
dir: ''
connections:
postgres:
main:
schema: drakkar # DSN from DK_CONNECTIONS__POSTGRES__MAIN__DSN
recorder:
provider: postgres
postgres:
connection: main
initial_retention: 6h
autodiscover:
enabled: true
provider: postgres
connection: main
Points to check:
- Size the database first: one busy worker writes about 9 GB per hour, 54 GB at a retention of 6 hours. See Write volume.
- The role of the connection must own the events table. With an operator-managed schema, run once as a role with the DDL rights, then give the table to the worker role:
drakkar-schema postgres --schema=drakkar --recorder --retention-hours=6 | psql "$ADMIN_DSN"
psql "$ADMIN_DSN" -c 'ALTER TABLE drakkar.recorder_events OWNER TO drakkar_worker'
- A worker uses up to 7 server connections with the defaults (1 for the
recorder writes, up to 2 history searches, the shared pool of 1 to 4).
Size
max_connectionsfor every worker. - While Postgres is down, the pipeline keeps running; rows wait in a bounded queue, and only that bound drops rows. See While Postgres is down.
Kubernetes probes¶
Drakkar exposes two dedicated HTTP endpoints for Kubernetes probes on the
API-server port (api.port, default 8080):
| Endpoint | Purpose | Success | Failure |
|---|---|---|---|
/healthz |
Liveness | 200 |
Restart the pod |
/readyz |
Readiness | 200 |
Remove the pod from endpoints |
Both endpoints are unauthenticated — they are the only routes on the
API server that ignore ui.auth_token. This is intentional: the
kubelet has no facility to supply bearer tokens on probe requests, and
both endpoints expose only liveness / readiness signals with no message
content, partition state, or operator credentials. They must be mounted
for Kubernetes integration to work.
Probe semantics¶
-
/healthz— returns{"status": "ok"}as long as the process is running and the FastAPI event loop is responsive. A/healthzfailure means the process is hung or crashed; the kubelet will restart the pod. -
/readyz— returns{"status": "ready"}only when the worker has completed its startup sequence (consumer subscribed, sinks connected, first poll cycle completed), every registered sink is currently connected, and no partition’s processing loop has died. Otherwise returns{"status": "not_ready", "reasons": [...]}with a 503 status code and a list of machine-readable reasons (e.g."not_started","sink_kafka:results_not_connected","partition_3_processor_died"). Withsplit.http.enabledthe worker is also not ready until it has read the status topic of HTTP split jobs; the reason is"split_http_status_not_restored". The kubelet removes the pod from the service endpoints on failure but does NOT restart it — the worker is considered recoverable and will self-register once ready.
Dead partition loops¶
A partition’s processing loop can exit on an unexpected error — a handler bug, a dependency that fails in a way the framework does not model. Left alone this is invisible: Kafka keeps the partition assigned, the consumer keeps enqueuing, and the queue grows with nothing draining it while offsets stop committing.
The framework restarts a dead loop once. A second death is treated as
a deterministic fault: the partition is marked dead, a CRITICAL
partition_processor_died log records the cause and the impact, and
/readyz starts failing with partition_<id>_processor_died. The
pod leaves the service endpoints and, once replaced, the partition is
reassigned to a healthy worker.
Until then the poll loop pauses the dead partition in Kafka, once
(partition_paused_on_death; partition_death_pause_failed if the
pause call fails), so its queue stops growing. The partition stays paused
through every backpressure resume and debug resume, and its queue does not
count toward sources.kafka.max_queued_messages, so it cannot hold the
other partitions paused.
drakkar_partition_processor_deaths_total{partition,outcome} counts
both paths — outcome="restarted" and outcome="dead". Alert on any
non-zero rate: a restart is a warning, a death means that partition is
stalled until the worker is replaced.
Note what a restart does not do. Offsets are registered before the
handler’s arrange runs, so a crash there leaves that window’s offsets
uncommitted for the life of the process, and the commit watermark stops
behind them. The restarted loop keeps processing, but its lag climbs until
a rebalance or restart hands those offsets to an owner that redelivers
them. That is the correct at-least-once outcome — those messages were
never processed, so committing past them would lose them.
Detached workers and stop requests¶
A worker that is detached from its Kafka consumer group stays
healthy and ready: /healthz and /readyz keep answering 200. Its
partitions are on the other workers of the group, so there is nothing to
fail over. A failing /readyz would only take the pod out of the Service
endpoints, and a failing /healthz would make the kubelet restart a
worker that is working as asked.
The handler can stop the worker with self.request_stop(reason, exit_code)
when it cannot work at all, for example when its work directory is gone. A
refused detach is no reason to stop: request_stop checks neither the
budget of detached workers nor min_attached, so a rule that stops every
worker that cannot detach can stop a whole group. The stop is the same graceful shutdown
as on SIGTERM: /readyz answers 503 from its start, the drain
settles the work in progress, and the process exits with exit_code
(0 to 255) after a clean shutdown. The worker logs stop_requested with
the reason and the code.
What happens next is the job of the supervisor:
- A Kubernetes
DeploymentorStatefulSetruns its pods withrestartPolicy: Always: the kubelet starts the container again with any exit code, on the same node. A stop does not move the worker away from a slow host. - A supervisor that restarts only on failure (
restartPolicy: OnFailurefor aJob,Restart=on-failurefor systemd) needs an exit code other than0. - Nomad moves an allocation to another node only after its restart attempts on the same node.
Read the exit code in your alerts: a code that your handler chose (for
example 3 for “slow disk”) says why the worker stopped.
Example probe configuration¶
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /readyz
port: 8080
periodSeconds: 5
failureThreshold: 3
initialDelaySeconds: 10
The initialDelaySeconds: 10 on the readiness probe accommodates the
worker’s cold-start sequence: loading config, connecting to Kafka, and
bringing up sinks. Tune upward if the cluster-align wait
(sources.kafka.startup_align.enabled) or a large sink fleet extends the
cold-start budget.
Rolling restarts¶
During a rolling restart the readiness probe flips /readyz to 503
as soon as _shutdown begins — well before sinks are torn down.
Kubernetes removes the pod from the service endpoints immediately, so
in-flight traffic drains to healthy replicas while the stopping pod
finishes committing offsets, draining executors, and closing sinks.
Liveness continues to return 200 until the process actually exits, so
the kubelet does not interpret the graceful-shutdown window as a crash.
A rolling restart that changes a cluster periodic task (its schedule or its
lease) leaves workers of one cluster with different definitions for a
while: they log periodic_cluster_mismatch and
drakkar_periodic_cluster_mismatch_peers is above zero until the last
worker restarted. See Definition hash.
Worker names and own folders¶
Every worker keeps its own files in <storage.dir>/<cluster>/<worker>/
(see The own folder). storage.dir
must be a local filesystem; put the network mount in storage.shared_dir.
With no worker.name and no value in the variable named by
worker.name_env (WORKER_ID by default), the worker name is the host
name, made safe (see Worker names):
- In Kubernetes the host name is the pod name. A container restart in the
same pod (an OOM kill, a crash) keeps the name, and an
emptyDirvolume survives the container restart, so the restarted worker finds its own folder: the watchdog reports the kill, the leftover recorder files are sealed, and the cache file is used again. - A StatefulSet keeps the pod name across pod recreation too.
- A Deployment gives a recreated pod a new name. With a persistent volume
the old folder is then an orphan,
sealed by another worker of the cluster only when
autodiscoveris on. Sealed files of names that are gone are archived only by the cluster scope, which needsautodiscoverandstorage.shared_dir; the own scope of a living worker never takes them. - In Docker the host name is the container id, which a restart of the same container keeps.
Two workers on one host with no configured name get the same name. On one
storage.dir the owner lock refuses
the second one, and with autodiscover on the
same-name check refuses a live twin on any
host. Set worker.name_env to a variable that is unique per worker when
several workers share a host.
Sudden restart (kill -9, OOM, host crash)¶
What happens to the files is in After a crash. On the Kafka side:
- The consumer commits manually and has no static group membership. After a
kill -9the broker keeps the dead member’s partitions assigned untilsources.kafka.session_timeoutpasses (45 seconds by default); nothing reads them in that time. - The restarted process joins as a new member, which starts a rebalance.
- The new owner of each partition starts at the last committed offset: the highest completed offset of an unbroken run, plus 1. Every message at or above it is read again: messages that waited in the partition queues, messages whose tasks were running, and messages that completed after an older one that had not. With a large fan-out, one incomplete message can hold back many completed ones. Their sink writes happen again (at-least-once). The recorder events of the dead process for those messages stay in its sealed file, so the history shows two runs.
- The subprocesses of the dead worker run in their own session, so a
kill -9of the worker does not kill them. In a container they end with the container. On a bare host they run until they finish, and their output goes nowhere. - After a quick restart the same-name check can hold the start for about one heartbeat (12 seconds with the defaults) while it confirms that the old card stopped moving.