A Kubernetes controller that manages tenant resources based on DynamoDB records.
The Tenant Controller watches a DynamoDB table for tenant configurations and automatically creates/updates/deletes the corresponding Kubernetes resources (Deployments and ConfigMaps) based on the table records.
- Kubernetes cluster
- AWS credentials with access to DynamoDB
- Docker
The DynamoDB table should have the following attributes:
name
(String) - Tenant namespec
(String) - JSON string containing the Deployment manifestcustomizations
(String) - JSON string containing an array of ConfigMap manifestsdeleted
(Boolean) - Flag indicating if the tenant resources should be deleted
docker build -t tenant-controller:latest .
- Create the necessary RBAC resources and deploy the controller:
kubectl apply -f k8s/deployment.yaml
- Make sure to set up AWS credentials. You can do this by:
- Using AWS IAM roles for service accounts (IRSA)
- Using environment variables
- Using AWS credentials mounted as a secret
The following environment variables are available:
DYNAMODB_TABLE
(required) - Name of the DynamoDB table to watch
- The controller watches the specified DynamoDB table for changes
- When a new tenant is added or updated:
- Creates/updates the Deployment from the
spec
field - Creates/updates ConfigMaps from the
customizations
field
- Creates/updates the Deployment from the
- When a tenant is marked as deleted:
- Deletes the corresponding Deployment and ConfigMaps
- Periodically reconciles the state to ensure Kubernetes resources match the DynamoDB records
{
"name": "tenant-1",
"spec": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "tenant-1-app",
"namespace": "default"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "tenant-1"
}
},
"template": {
"metadata": {
"labels": {
"app": "tenant-1"
}
},
"spec": {
"containers": [
{
"name": "app",
"image": "nginx:latest"
}
]
}
}
}
},
"customizations": [
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "tenant-1-config",
"namespace": "default"
},
"data": {
"config.json": "{\"key\": \"value\"}"
}
}
],
"deleted": false
}