7.1 KiB
Project: Memelord Jake
Project Overview
This project defines the Kubernetes deployment and configuration for a Django application named "memelord". The application is designed for cloud-native environments, leveraging Kubernetes for orchestration, PostgreSQL as its primary database, Redis (DragonflyDB) for caching/sessions, and an S3-compatible object storage (MinIO/Onyxia S3) for media files. Authentication is handled via OpenID Connect (OIDC) using a service called "Passmower". The setup also includes Grafana for monitoring, which is similarly integrated with OIDC.
Architecture
The project's architecture is built around several interconnected services deployed within a Kubernetes cluster:
- Memelord Application: A Django application running in a Kubernetes Deployment, serving on port 8000. It uses a Docker image (
ghcr.io/l4rm4nd/memelord:latest). - Database: A PostgreSQL database managed by CloudNativePG (
postgresql.cnpg.io) is used for persistent data storage. - Cache/Session Store: Redis, deployed via DragonflyDB (
dragonflydb.io), serves as a caching layer and for Django session management. - Object Storage: An S3-compatible service (MinIO, managed by Onyxia S3 custom resources) is used for storing application media, configured with policies and user credentials.
- Authentication: OpenID Connect (OIDC) is integrated for user authentication, with client configurations defined for both the "memelord" application and Grafana.
- Monitoring: Grafana is deployed as a StatefulSet, configured with Prometheus and Loki datasources, and protected by OIDC authentication.
- Networking: Kubernetes Services expose the applications internally, while Ingress resources (using Traefik) provide external access with TLS certificates managed by cert-manager.
Key Configuration Files
The project relies heavily on Kubernetes YAML manifests for its configuration and deployment:
app.yaml: Defines the main KubernetesDeploymentfor thememelordapplication. It specifies the Docker image, container ports, and critical environment variables for database, Redis, S3, and OIDC connectivity. It also mounts asettings.pyfrom a ConfigMap.config.yaml: Contains a KubernetesConfigMapnamedsettings, which provides thesettings.pyfile for the Django application. This file dynamically configures various aspects of the Django project based on environment variables, including database backend, Redis caching, security headers (CSP, HSTS), logging, and different cloud storage providers (S3, Azure, GCS, SFTP, Dropbox). It also integratesmozilla_django_oidcif OIDC is enabled.deployment.yaml: A comprehensive manifest defining the backing services for thememelordapplication. This includes:StringSecretandDragonflyfor Redis (memelord-jake-redis).StringSecret,Cluster, andDatabasefor PostgreSQL (memelord-jake-database).Policy,S3User, andBucketfor S3 object storage (memelord-jake).- A Kubernetes
ServiceandIngressfor thememelordapplication, includingCertificatesetup for TLS.
grafana.yaml: Defines the Kubernetes resources for deploying and configuring Grafana. This includes:- A
Namespace(memelord-jake). ConfigMapfor Grafana's Prometheus and Loki datasources.- A
StatefulSetfor Grafana, configuring it for SQLite storage and integrating Generic OAuth for OIDC authentication. - A Kubernetes
Service,Certificate, andIngressfor Grafana. - An
OIDCClientcustom resource for Grafana's OIDC setup.
- A
oidc.yaml: Defines anOIDCClientcustom resource specifically for thememelord-jakeapplication, detailing its OIDC redirect URIs, grant types, response types, and available scopes for authentication.
Deployment
This project is designed to be deployed to a Kubernetes cluster. The entire environment, including the application, database, Redis, S3, and Grafana, can be deployed by applying these YAML manifests.
To deploy the application and its dependencies to a Kubernetes cluster, you would typically use kubectl apply -f for each of the YAML files in the directory.
kubectl apply -f app.yaml
kubectl apply -f config.yaml
kubectl apply -f deployment.yaml
kubectl apply -f grafana.yaml
kubectl apply -f oidc.yaml
Note: The .yaml files define custom resources that require specific Kubernetes operators (e.g., CloudNativePG, DragonflyDB, Onyxia S3, cert-manager, Traefik, Codemowers Cloud OIDC) to be installed in the cluster.
Development Notes
The Django application is heavily configured via environment variables, as seen in config.yaml (settings.py). This allows for flexible configuration depending on the deployment environment (development, staging, production). Secrets (like database passwords and API keys) are injected into the application containers via Kubernetes Secret resources, often generated by StringSecret custom resources for enhanced security.
The settings.py includes robust security practices such as Content Security Policy (CSP), HSTS, and secure cookie settings. It also supports various file storage backends, making it adaptable to different cloud providers.
Monitoring
Grafana is included in the deployment to provide monitoring capabilities. It is pre-configured with Prometheus and Loki datasources, allowing for the visualization of metrics and logs from the deployed services. Access to Grafana is secured via OIDC.
Training Context (Koolitus 2026)
This project was developed as part of a Kubernetes training (Koolitus 2026). The following tasks and configurations were implemented based on the training requirements:
Tuesday Tasks
- ConfigMap Integration: Mounted
settings.pyfrom aConfigMapinto the Memelord deployment at/opt/app/myproject/settings.pyusingsubPathto avoid overwriting the entire directory. - S3 Configuration: Set
AWS_S3_ADDRESSING_STYLE = 'path'in Django settings. - ArgoCD: Configured ArgoCD to track the repository, deploying into the
memelord-jakenamespace with a destination cluster athttps://10.254.10.31:6443. - Grafana Setup:
- Deployed as a
StatefulSetusing thesqlitestorage class (5Gi volume). - Configured Ingress with TLS (
cert-manager). - Integrated OIDC authentication via Passmower.
- Provisioned Prometheus (
http://prometheus-operated.monitoring.svc.cluster.local:9090) and Loki (http://loki.monitoring.svc.cluster.local:3100) datasources.
- Deployed as a
Wednesday Tasks
- Architectural Review: Discussion on
DeploymentvsStatefulSetvsDaemonSet. - Observability: Implementation of Prometheus metrics and Loki logs.
- Declarative Grafana: Configuring datasources via Kubernetes manifests (as seen in
grafana.yaml).
LLM Integration (Optional Context)
The training environment included access to LLMs via https://llama-api.ee-lte-1.codemowers.io and a WebUI at https://llm.ee-lte-1.codemowers.io/. A sample StatefulSet for open-webui was provided as a challenge to integrate SSO and PostgreSQL.