Production Deployment
A production deployment of Smarter runs on Kubernetes, on any cluster: a cloud provider’s managed Kubernetes, or your own cluster, wherever it runs, including your own data center. At a high level, you’ll be performing the following three steps:
Identify the common settings that are needed by both the cloud infrastructure and the Kubernetes deployment.
Build the cloud infrastructure: the Kubernetes cluster, and for each environment its namespace, DNS, certificates, email, storage and credentials. smarter-infrastructure builds all of it with Terraform on AWS, with Azure and Google Cloud to follow. On another cluster, you provide these yourself.
Deploy the Kubernetes pods, with the Smarter Helm chart: the application server, the Celery workers, Celery Beat, MariaDB and Redis.
The infrastructure must exist before the pods are deployed. The Helm chart installs into the environment’s namespace, and reads the database, administrator, email and Django credentials from the Kubernetes Secrets there.
Step 1: Identify the common settings
These are the root values used for naming key resources. smarter-infrastructure and the Helm chart each need them, and they must agree. These values are not easily changed after a deployment, so choose them carefully.
Value |
Example |
smarter-infrastructure |
Helm values |
|---|---|---|---|
Root domain |
|
|
|
Platform subdomain |
|
|
|
AWS region |
|
|
|
Environment |
|
one folder per environment, |
|
A Route53 hosted zone for the root domain must already exist in your AWS account.
Step 2: Build the cloud infrastructure
smarter-infrastructure builds everything with Terraform and Terragrunt, a wrapper that applies the same Terraform to several environments. You don’t need to change its code, apart from the one line below. Its README and Makefile explain each command.
Danger
Running cloud infrastructure costs money. The cluster, its nodes, the load balancer, CloudFront and
the rest are billed by AWS from the moment they are created. Review AWS’s pricing for each before you
apply. Expect to spend at least a few hundred US dollars per month for a production deployment,
and more if you run multiple environments. Delete the infrastructure when you don’t need it, with
make destroy in smarter-infrastructure.
Clone smarter-infrastructure, and run
maketo create its.env. Fill it in:Variable
Required
What it is
ROOT_DOMAIN,PLATFORM_SUBDOMAIN,AWS_REGIONyes
The common settings, from Step 1.
AWS_ACCOUNT_IDyes
The AWS account.
AWS_PROFILEyes
The AWS credentials that Terraform runs with, an administrator’s.
IAM_ADMIN_USER_ARNyes
The IAM user who administers the cluster.
MYSQL_ROOT_USERNAME,MYSQL_ROOT_PASSWORDyes
The database server’s administrator.
DOCKER_USERNAME,DOCKER_PATyes
A Docker Hub account and access token, for the cluster’s image cache.
UNIQUE_IDyes
A suffix that makes the cluster’s name unique, e.g. the date,
202602121853.UPTIME_ALERT_EMAILno
Where the uptime checks send their alarms.
COST_CODEno
A tag on every resource. Default
smarter.In
aws/terraform/smarter/providers.tf, set the Kubernetes provider’sconfig_contextto your cluster’s kubeconfig context. It names the maintainers’ cluster.Build the shared infrastructure, once: the VPC, the Kubernetes cluster, then its ingress, certificate manager and descheduler.
cd aws/stack && terragrunt run --all applyapplies them in that order.Build each environment. For an environment other than
prodoralpha, copy one of their folders underaws/environments/and change itsenvironment. Thencd aws/environments/<environment> && terragrunt apply. This creates the environment’s namespace, its Kubernetes Secrets, IAM roles, DNS zones, certificates, SES email, S3 buckets and CloudFront distribution.Note three values for Step 3: the cluster’s name, the output
cluster_nameofaws/stack/kubernetes; and the IAM roles of the pods, one per kind of pod, and of the nightly database backup, the outputssmarter_pod_iam_role_arnsandsmarter_backup_iam_role_arnofaws/environments/<environment>. Read each withterragrunt output <name>in its folder.
Warning
Don’t build or change these resources by hand. They depend on each other, and Terraform tags each one, which is how you find them in your AWS account afterwards.
Step 3: Deploy the Kubernetes pods
The Helm chart installs Smarter into the environment’s namespace. It reads the database, administrator, email and Django credentials from the Kubernetes Secrets that smarter-infrastructure created there, so your values file holds only the settings below.
Tip
The smarter repository’s GitHub Actions workflow
Deploy already does
every part of this step: it connects to the cluster, writes the values file from GitHub Actions
secrets, and runs helm upgrade --install, on every release. Use it as the model for automating your
own deployments.
On the computer that you run
helmfrom, connectkubectlandhelmto the cluster. On AWS:aws eks update-kubeconfig --region <region> --name <cluster name>
On that computer, create a file named
my-values.yaml, in any folder. The next step passes it tohelm. It holds API keys, so don’t commit it to a repository.This is the minimum set of values. On a cluster that smarter-infrastructure built, the deployment needs each of these values.
env: SMARTER_ENVIRONMENT: "prod" SMARTER_PLATFORM_ROOT_DOMAIN: "example.com" SMARTER_PLATFORM_SUBDOMAIN: "platform" AWS_REGION: "ca-central-1" SMARTER_SUBSYSTEM_K8S_CLUSTER_NAME: "smarter-platform-ca-202602121853" SMARTER_PLATFORM_FERNET_ENCRYPTION_KEY: "<a URL-safe base64-encoded 32-byte key>" DOCKERHUB_USERNAME: "<DOCKER_USERNAME>" DOCKERHUB_PAT: "<DOCKER_PAT>" bootstrapSecrets: openai_api_key: "<your OpenAI API key>" serviceAccount: awsRoleArns: api: "<smarter_pod_iam_role_arns.api>" worker: "<smarter_pod_iam_role_arns.worker>" worker-infrastructure: "<smarter_pod_iam_role_arns.worker-infrastructure>" job-init: "<smarter_pod_iam_role_arns.job-init>" createClusterRole: false databaseScheduledBackup: awsRoleArn: "<smarter_backup_iam_role_arn>"
Value
What it is
env.SMARTER_ENVIRONMENT,_PLATFORM_ROOT_DOMAIN,_PLATFORM_SUBDOMAIN,env.AWS_REGIONThe common settings, from Step 1.
env.SMARTER_SUBSYSTEM_K8S_CLUSTER_NAMEThe cluster’s name, from Step 2. Smarter deploys LLMClients into it.
serviceAccount.awsRoleArns,databaseScheduledBackup.awsRoleArnThe IAM roles, from Step 2: one per kind of pod that calls AWS, with only what it does there, and the backup’s. Celery Beat and the migrate Job have none.
createClusterRole: false: smarter-infrastructure has already created the pods’ cluster roles.env.SMARTER_PLATFORM_FERNET_ENCRYPTION_KEYThe key that Smarter encrypts Secrets with. Without it, each pod generates its own key, and a Secret saved by one pod can’t be read by another, or after a restart.
env.DOCKERHUB_USERNAME,env.DOCKERHUB_PATThe Docker Hub account from Step 2, which pulls Smarter’s image. Only the chart’s image-pull Secret holds them: unlike the rest of
env, they reach no pod’s environment.bootstrapSecrets.openai_api_keyOpenAI is the default LLM provider, and the example resources and Stackademy use it. Each key under
bootstrapSecretsbecomes a Smarter Secret of that name, owned by the Smarter admin. The chart puts them in the Kubernetes Secretsmarter-bootstrap-secrets, which only the init job mounts, andmanage.py initialize_bootstrap_secretscreates the Smarter Secrets from it. No other pod receives them, as environment variables or files.What else can go in the file. Five kinds of values, each to change a default or turn on a feature:
Kind
In the file
Where to find the names
Smarter settings
env.SMARTER_<SETTING>The chart’s values.yaml lists every one, with its default, spelled exactly as your file must spell it.
SMARTER_PLATFORM_ROOT_DOMAINsets the settingplatform_root_domain, and so on, which Smarter Settings describes.Resource types, on or off
env.SMARTER_APP_<APP>_ENABLEDjango settings
env.DJANGO_<SETTING>Any setting of Django, or of a Django package that Smarter uses: Django’s settings reference. Yours replaces Smarter’s value outright; read Overrides first.
The chart’s own options
top-level keys, e.g.
app,hpa,worker,beat,databaseInit,databaseScheduledBackup,slackBot,bootstrapSecretsThe chart’s values.yaml: replicas, resources, autoscaling, the init job, the nightly backup, and the Slack bot.
MariaDB and Redis
mariadb.*,redis.*The Bitnami charts that the chart installs them with: mariadb and redis.
The Smarter settings that most deployments add:
Value
What it is
env.SMARTER_PLATFORM_EMAIL_ADMINThe administrators’ email address.
env.SMARTER_PLATFORM_BRANDING_*Your organization’s name, address, support email, contact URL and logo, as the web console and its emails show them. Unset, they show The Smarter Project’s.
bootstrapSecrets.anthropic_api_key,gemini_api_key,mistral_api_key, …The other LLM providers. The chart’s
values.yamllists every Secret name.bootstrapSecrets.google_maps_api_key,tavily_api_key,brave_search_api_key,pinecone_api_keyTools and vector stores that the example resources use.
env.SMARTER_SUBSYSTEM_SOCIAL_AUTH_*Sign-in with Google, GitHub or LinkedIn.
env.SMARTER_SUBSYSTEM_SLACK_BOT_TOKEN,databaseInit.notifySlackChannelThe init job’s and the nightly backup’s notices in Slack.
env.SMARTER_SUBSYSTEM_SQL_BACKUP_PASSWORDA read-only database account for the nightly backup. Unset, the backup uses the root account.
Install the chart into the environment’s namespace,
smarter-<subdomain>-<environment>:helm upgrade --install smarter oci://ghcr.io/smarter-sh/charts/smarter \ --version <chart version> \ --namespace smarter-platform-prod \ --values my-values.yaml \ --timeout 900s
The chart versions are listed on Artifact Hub. To upgrade, run the same command with the new version.
On a fresh install, the pods wait until the chart’s init job has created and migrated the database. The
init job then runs manage.py initialize_platform, which creates the administrator, the built-in
providers, the example resources and Stackademy. See
Smarter on Kubernetes.
When it’s done, sign in at https://<subdomain>.<root domain>/, e.g. https://platform.example.com/,
as admin, with the password in the Kubernetes Secret smarter-admin:
kubectl get secret smarter-admin -n smarter-platform-prod \
-o jsonpath='{.data.SMARTER_ADMIN_PASSWORD}' | base64 --decode
What the running platform uses
With the chart’s default of one replica of each (global.replicaCount: 1, the lite deployment; see
Operating Smarter at Scale), the platform’s own pods reserve 1.2 vCPU,
their CPU requests, which decide how many pods fit on a node. Idle, they use about 2.1 GiB of memory:
Pod |
Replicas |
Processes |
CPU request |
Memory per pod, idle |
|---|---|---|---|---|
|
1 |
one uvicorn worker |
250m |
about 340 MiB |
|
1 |
Celery prefork, 5 children |
250m |
about 590 MiB, after running the deploy’s tasks |
|
1 |
Celery prefork, 4 children |
250m |
about 400 MiB |
|
1 |
Celery threads, 4 threads in one process |
250m |
about 280 MiB |
|
1 |
Celery prefork, 2 children, one per Extension call |
100m |
about 310 MiB |
|
1 |
one |
100m |
about 270 MiB |
A pod’s memory grows with the work it has done, and Python rarely returns memory to the operating system,
so a pod that has run tasks or served requests stays above its size at start: smarter-worker, which ran
the init job’s tasks, started at about 370 MiB, and smarter-api at about 280 MiB. With
global.replicaCount: 3, the production deployment, the api, smarter-worker, the tool worker and the
Extension worker each run three of these pods.
The init job uses about 300 MiB while it runs. MariaDB (about 330 MiB), Loki (about 75 MiB), Alloy (about 65 MiB), the Slack bot (about 25 MiB), Redis (about 15 MiB) and the egress proxy (under 10 MiB) add the rest.
Each Python process that loads Smarter costs about 290 MiB, so the number of processes per pod sets most
of this. That’s why each app pod runs one uvicorn worker, and the chart scales the app with replicas
(hpa) rather than with workers per pod. The tool worker runs Celery’s threads pool, because its
tasks wait on the network. The prefork workers’ children share their parent’s memory, which Smarter
freezes out of the garbage collector’s reach before the pool forks. Packages that few code paths need,
such as the vector store and SSH clients, are imported where they are used, not at startup.
How many nodes. Kubernetes places pods by what they request, not by what they use, so the chart’s
requests (resources in each pod’s section of values.yaml), not the table above, decide how many
nodes an environment needs. With the chart’s defaults, one environment at rest requests:
Node pool |
Nodes for one environment |
Approximate monthly cost |
What decides it |
|---|---|---|---|
The cluster’s shared pool: spot instances of 2 vCPU and 8 GiB, e.g. t3.large (1.93 vCPU, 6.91 GiB
and 20 pods allocatable), with |
0.73 |
about $16 |
CPU. The app, Celery and Beat pods, the egress proxy, Alloy, the bastion and the Slack bot request 1.41 vCPU, 3.87 GiB and 10 pods: 0.73 nodes’ CPU, 0.56 nodes’ memory, and 0.50 nodes’ pods. The Celery workers request 2.38 GiB of it. |
The same shared pool, with |
1.66 |
about $36 |
CPU. The same pods, with three of the app, each Celery worker but the infrastructure one, and the egress proxy, request 3.21 vCPU, 8.73 GiB and 20 pods: 1.66 nodes’ CPU, 1.26 nodes’ memory, and 1.00 nodes’ pods. The Celery workers request 5.88 GiB of it. |
The environment’s stateful pool: one on-demand t3.medium |
1.00 |
about $34 |
Fixed. MariaDB, Redis and Loki, which must not move when a spot node is reclaimed. |
The costs are in US dollars, in ca-central-1, for 730 hours a month: a t3.large on spot at about $0.030 an hour (about $22 a month, against $68 on-demand), and a t3.medium on-demand at $0.0464 an hour. Spot prices change by the hour and by availability zone, and the cluster bills whole nodes, so a lone lite environment pays for at least one shared node, about $22. They leave out the EKS control plane, the load balancer, EBS volumes, data transfer and Route53.
So each environment has a baseline cost of around $50 a month.
These figures leave out the DaemonSets that run on every node (the VPC CNI, kube-proxy and the EBS CSI driver), which take a little of each node’s CPU and a few of its pod slots. At rest, a lite environment fits on one shared node with room for two more pods, enough for a small burst; a bigger one, or a deploy, which starts each new pod before it stops the old one, needs a second. Plan for one or two shared nodes for a lite environment, at least two for a production one, and one stateful node for either. Every other environment on the same cluster adds its own share of the shared pool and its own stateful node. smarter-infrastructure sets the instance types and the shared pool’s minimum and maximum size; the cluster autoscaler adds and removes shared nodes between them.
Under load, the autoscalers add replicas, the app’s hpa and each worker’s keda.workers, and each
replica needs room on a shared node for what it requests:
Pod |
CPU request |
Memory request |
Share of a t3.large |
|---|---|---|---|
|
0.25 vCPU |
0.63 GiB |
0.13 |
|
0.25 vCPU |
0.88 GiB |
0.13 |
|
0.25 vCPU |
0.63 GiB |
0.13 |
|
0.25 vCPU |
0.44 GiB |
0.13 |
|
0.10 vCPU |
0.44 GiB |
0.06 |
A pod’s share is the larger of its CPU and its memory, as a fraction of the node’s allocatable. Each deploy also needs room for a while: the init job, and the new pods that a rolling update starts before it stops the old ones.
Trouble Shooting
Permissions and naming are the two most common causes of deployment problems. The Kubernetes Ingress manifest below holds eleven names, made by either Terraform or Smarter, that have to agree.
How resources are named
smarter-infrastructure and Smarter derive the names of a broad range of resources from the common
settings in Step 1. The names must agree, or the deployment fails. In these examples, the root
domain is example.com and the platform subdomain platform.
Resource |
Name |
prod / alpha |
|---|---|---|
Kubernetes cluster |
|
one for every environment |
Kubernetes namespace |
|
|
Platform domain, and S3 bucket |
|
|
API domain |
|
|
CDN domain |
|
|
Backup and export buckets |
|
|
IAM roles |
|
|
Database and its user |
the namespace, with |
|
The ca in the cluster’s name is fixed in smarter-infrastructure’s aws/global.hcl, whatever the
region.