Smarter on Kubernetes
Smarter runs in two kinds of environment, and the same Docker image serves both:
Docker, with
docker-compose.yml, on a developer’s computer. Every service runs as one container on one machine, the web console is served onhttp://localhost:9357, and nothing is reachable from the internet.Kubernetes, with the Smarter Helm chart, in production. The platform runs as several Deployments that scale horizontally, behind a load balancer, and every deployed LLMClient gets its own hostname, DNS record, Kubernetes Ingress and TLS certificate.
The Python code is the same in both. What differs is the infrastructure around it, and that difference matters most when an LLMClient is deployed: in Docker, deploying an LLMClient changes a row in the database; in Kubernetes, it also creates cloud and cluster resources that someone has to support.
This section is for the people who install, operate and support Smarter in production: platform engineers, SREs, and the administrators who answer “why isn’t my LLMClient reachable?”. ADR-002 and ADR-003 record why Smarter chose Docker and Kubernetes (AWS EKS) in the first place.
The Services
Both environments run the same processes. Only how they are started, scaled and connected differs.
Process |
Docker ( |
Kubernetes (Helm chart) |
|---|---|---|
Web application and REST API |
|
Deployment |
Operational Celery worker |
|
Deployment |
Infrastructure Celery worker |
|
Deployment |
Tool Celery worker |
|
Deployment |
Celery Beat |
|
Deployment |
Database and cache |
|
MySQL or MariaDB and Redis, inside the cluster or managed by the cloud
( |
The two Celery queues are separate on purpose. The infrastructure queue carries the slow tasks that deploy, verify and destroy DNS records, ingresses, certificates, node groups and databases, so that they can never delay the operational tasks that record prompt history, charges and budgets. See ADR-030.
The Helm chart also runs a Job, smarter-job-init, on every install and upgrade. It migrates the
database, initializes the platform, loads the example resources and deploys the built-in LLMClients.
On a new cluster, that one Job queues a deployment for every built-in LLMClient at once.
Before an upgrade’s rollout, a second Job, smarter-job-migrate, a pre-upgrade hook, runs only
manage.py migrate, so that the new release’s pods never take requests before the columns and
tables that their code reads exist. smarter-job-init runs after the rollout, and its migrate then
has nothing left to do. A failed migration fails helm upgrade before any pod is replaced. Until
the rollout finishes, the previous release’s pods run against the new schema, which is why a
migration that removes or renames a column needs two releases: one that stops reading it, then one
that drops it. On a fresh install, there is no pre-install
migration: the chart’s Secret doesn’t exist yet, and smarter-job-init creates the database
before it migrates. Meanwhile the pods of the app, the Celery workers and beat wait in an init
container that retries manage.py migrate --check every 10 seconds, so that they start on a
migrated database, rather than answering errors and restarting until the Job is done. The init
container is rendered only on an install, so an upgrade’s pods start without it.
smarter-job-init runs once: a failed step fails it, and Kubernetes doesn’t retry it
(backoffLimit: 0). The next deployment runs it again.
When it completes, it emails its whole log, with credentials redacted, to the chart’s
databaseInit.notifyEmail, or by default to the platform’s admin, SMARTER_PLATFORM_EMAIL_ADMIN, with
manage.py email_job_log. The email reports whether the Job succeeded, and carries the log as an
attachment. A log larger than 5 MB would exceed the SMTP server’s message size limit, so it is saved
instead to the platform’s public S3 bucket, under job-logs/ with an unguessable name, and the
email links to its CDN URL. The email is sent only when SMTP is configured (see
SMTP Email Support), and a Job that is killed, for example for running out of memory, sends
none.
The Job can also post its outcome to a Slack channel, databaseInit.notifySlackChannel (empty by
default, which posts nothing), with email_job_log --slack-channel. The message says whether the
Job succeeded, with ✅ or ❌, and the whole log, redacted, is uploaded into the message’s thread, as
the same file that the email attaches. It is posted as the bot of SMARTER_SUBSYSTEM_SLACK_BOT_TOKEN, which
needs the scopes chat:write and files:write, and must be a member of the channel. A bot
without files:write posts the log’s last lines in the thread instead, and the link to the log
when it was saved to S3. Text from the log is escaped, so that a log line can’t mention anyone.
Slack, like email, never changes the Job’s outcome. The deploy workflow passes the bot token to
every environment, and sets both jobs’ channel to smarter.
A CronJob, smarter-mysql-backup, backs up the database to S3 every night. See
Backup and Restore.
An optional Deployment, smarter-slack-bot (slackBot.enabled, false by default), answers
questions in a Slack workspace with a deployed LLMClient. See The Slack Bot.
Docker and Kubernetes Compared
Concern |
Docker |
Kubernetes |
|---|---|---|
Configuration |
A |
The |
Kubernetes namespace |
None is used. |
|
Hostnames |
|
|
TLS |
None: plain HTTP on localhost. |
cert-manager issues a certificate for every hostname, including one per deployed LLMClient. Custom Domains also get an ACM certificate, for the domain alone, which proves the domain’s delegation and is never served. |
Routing a request to an LLMClient |
Django resolves the LLMClient from the URL path (sandbox URLs). |
Traefik routes the hostname to the |
Deploying an LLMClient |
Sets |
Creates a DNS A record, an Ingress, a cert-manager Certificate and a TLS Secret, then verifies them. See LLMClient Deployment. |
Scaling |
One container per service. |
HorizontalPodAutoscalers for the app and the operational worker; the app’s also scales
on memory, measured against |
Health checks |
None. |
Startup and liveness probes on |
Timeouts |
The same, except the database’s. |
Connecting to the database times out after 5 seconds, and to Redis after 2. A Redis
command times out after 5 seconds. The web server’s database queries time out after
|
Upgrades |
Rebuild the image and restart the containers. |
|
Logs |
|
|
Cloud resources |
None, normally. |
Route53 records, ACM certificates, EKS node groups (LLMHost) and StatefulSets with volumes (self-hosted vector stores), recorded in the infrastructure resource ledger. |
Warning
The deployment tasks act on whatever cloud credentials and kubeconfig their container has. If you
give a Docker environment real AWS credentials and a kubeconfig for a real cluster, deploying an
LLMClient locally creates real Route53 records and applies a real Ingress to the namespace
smarter-local of that cluster. To keep a Docker environment self-contained, leave the cloud
credentials out, or set SMARTER_APP_LLMCLIENT_TASKS_CREATE_DNS_RECORD=false and
SMARTER_APP_LLMCLIENT_TASKS_CREATE_INGRESS_MANIFEST=false.
How Smarter Talks to the Cluster
Smarter never calls the Kubernetes API from a client library. The
infrastructure services run
kubectl as a subprocess, with a kubeconfig that
the cloud provider writes (aws eks update-kubeconfig for EKS), and with the cloud identity of the
pod. Every pod that runs the image has kubectl and the AWS CLI installed, and KUBECONFIG
points at /home/smarter_user/data/.kube/config.
In practice, the infrastructure worker is the pod that changes the cluster: it applies and deletes Ingresses, and reads Certificates and Secrets. The permissions that this requires, and how to keep them small, are described in Operating Smarter at Scale.
Kubernetes, DNS and certificate calls all go through one facade,
smarter.apps.infrastructure.services.infrastructure, so the cloud is a configuration choice
(SMARTER_PLATFORM_CLOUD_PROVIDER), and tests replace it with an in-memory provider.
Cluster Prerequisites
The Helm chart installs Smarter itself. It does not install the cluster add-ons that LLMClient deployment depends on. Before the first LLMClient is deployed, the cluster needs:
Traefik as an ingress controller, with the
traefikIngressClass and thewebsecureentry point, exposed by a cloud load balancer.A Traefik Middleware named
https-redirectin the environment’s namespace. Every LLMClient Ingress refers to it as<namespace>-https-redirect@kubernetescrd.cert-manager, with a ClusterIssuer named after the environment’s API domain, e.g.
api.platform.example.comin production oralpha.api.platform.example.comin alpha. Every LLMClient Ingress names it in itscert-manager.io/cluster-issuerannotation.A DNS zone for the API domain, whose A record points at the load balancer. Every LLMClient’s A record is a copy of it.
An identity for the pods that can manage that DNS zone and the namespace’s Ingresses. See Operating Smarter at Scale.
The Smarter Terraform modules build this infrastructure on AWS. See Production Deployment.