How ezzeldinabdulhafiz/kubernetes-banking-platform works
1. Repository purpose
- This repo implements a Kubernetes-deployed banking platform with three runtime components: a PostgreSQL data tier, a Node.js API, and a static web dashboard.
- The core architecture is cloud-native and centered on Kubernetes resources rather than an in-process monolith.
2. Runtime subsystems
- app/banking-api is the application backend. It is a Node.js/Express service that exposes banking endpoints and talks to PostgreSQL through connection pooling.
- app/banking-dashboard is a static front end served by Nginx; it is the user-facing UI and consumes the API over HTTP.
- PostgreSQL runs as a StatefulSet with replication, so the database tier is stateful and pod-identity-aware.
3. Request/data flow
- User traffic enters through Kubernetes Ingress.
- Requests to / are routed to the dashboard service, which serves the browser UI.
- Requests to /api/... are routed to the API service, which performs reads/writes against PostgreSQL.
- The database layer is split into primary and replica pods; the API is configured to use primary for writes and replica for reads.
4. Application boundary
- The API is the main business-logic boundary: it owns account creation, transfers, transaction history, stats, and health/readiness endpoints.
- The dashboard is intentionally thin and presentation-only; it does not own data persistence.
- PostgreSQL is the system of record, with schema tables for accounts and transactions.
5. Kubernetes deployment model
- Everything is deployed into a dedicated banking namespace.
- The database is implemented as a StatefulSet because it needs stable identities and persistent storage.
- The API and dashboard are Deployments because they are stateless and horizontally replaceable.
- Services sit between pods and consumers: headless service for PostgreSQL discovery, ClusterIP services for API and dashboard.
6. Infrastructure and scheduling
- The cluster is expected to have labeled and tainted nodes, especially high-memory worker nodes and database-only taints for database placement.
- PostgreSQL pods tolerate database-only nodes and are spread with pod anti-affinity for availability.
- API pods also use anti-affinity, while the dashboard has its own scheduling constraints to keep placement predictable.
7. Configuration and secrets
- Runtime configuration is split between ConfigMaps and Secrets.
- The API receives database hostnames, port, DB name, and logging/transaction settings from config, while credentials come from a Secret.
- The database init script is injected via a ConfigMap-backed script in k8s/scripts/postgres-init.sh, which is used to bootstrap replication/setup behavior.
8. Security boundaries
- Pods run as non-root users and use hardened security contexts.
- The API container uses a read-only root filesystem and drops unnecessary privileges.
- NetworkPolicy, RBAC, and separate service accounts are present to constrain inter-pod and cluster access.
- Sensitive values are not baked into images; they are externalized in Kubernetes secrets.
9. Availability and scaling
- The API has multiple replicas, health checks, and is managed by HPA and VPA manifests for elasticity and resource tuning.
- PostgreSQL replication provides database-level resilience; anti-affinity and PVCs help protect against node loss.
- Probes (/health, /ready) are part of the API lifecycle, ensuring traffic only reaches healthy pods.
10. Observability and ops
- A Fluentd DaemonSet collects logs cluster-wide.
- The manifests include health, readiness, and resource constraints, indicating an emphasis on operational visibility and stability.
- The setup script is the operational entry point: it can create the cluster, configure nodes, build images, deploy manifests, show status, and clean up.
11. Packaging and delivery
- Each app component has its own Dockerfile, so images are built independently and deployed separately.
- setup.sh orchestrates the full lifecycle; it is the main automation boundary between local workstation and cluster deployment.
- The repo is therefore organized around infrastructure-as-code plus two containerized app artifacts, not around a single server application.
12. What an architecture diagram should show
- Three main tiers: browser/dashboard, API service, PostgreSQL cluster.
- Kubernetes control plane objects around them: namespace, services, ingress, StatefulSet/Deployments, ConfigMap/Secret, policies, autoscaling, logging.
- Clear directional flow from user → ingress → dashboard/API → database, with replication between PostgreSQL primary and replica.
Main entry points: app.js Banking API · 03-postgres-statefulset.yaml PostgreSQL · setup.sh Setup Script · 07-ingress.yaml Ingress
Components 16
Workloads
Application runtimes and user-facing traffic
- User · Browser user accessing the platform
- Dashboard · Presentation-only web UI served by Nginx
app/banking-dashboard/index.html - Banking API · Business logic for accounts, transfers, history, and health
app/banking-api/app.js
Platform
Kubernetes objects and data tier
- Ingress · Entry point routing web and API traffic
k8s/07-ingress.yaml - Dashboard Svc · Routes browser requests to the dashboard pods
k8s/06-services.yaml - API Svc · Stable endpoint for banking API traffic
k8s/06-services.yaml - PostgreSQL · Stateful database tier with stable identities and storage
k8s/03-postgres-statefulset.yaml - DB Svc · Discovery for PostgreSQL pods
k8s/06-services.yaml - Primary Pod · Write target for the API
k8s/03-postgres-statefulset.yaml - Replica Pod · Read replica used for read traffic
k8s/03-postgres-statefulset.yaml - ConfigMap · Non-secret settings and init script source
k8s/01-configmap.yaml - Secret · Database credentials and sensitive runtime values
k8s/02-secret.yaml - Autoscaling · Horizontal and vertical scaling policies for the API
k8s/08-hpa.yaml - Policy · Access control boundaries for pods and cluster traffic
k8s/10-rbac.yaml
Ops
Automation, security, and observability
- Fluentd · Cluster-wide log collection
k8s/12-daemonset-fluentd.yaml - Setup Script · Lifecycle automation for cluster creation, deploy, status, and cleanup
setup.sh
Connections 26
- User → Ingress: HTTP traffic · Browser traffic enters the cluster through ingress
- Ingress → Dashboard Svc: / · Routes root requests to the dashboard
- Ingress → API Svc: /api · Routes API requests to the banking backend
- Dashboard Svc → Dashboard: serves · Cluster service targets dashboard pods
- API Svc → Banking API: serves · Cluster service targets API pods
- Banking API → DB Svc: connects · API reaches the database through discovery service
- DB Svc → Primary Pod: discover · Primary identity used for writes
- DB Svc → Replica Pod: discover · Replica identity used for reads
- Banking API → Primary Pod: writes · Account and transaction updates go to the primary
- Banking API → Replica Pod: reads · Read-heavy queries can use the replica
- Primary Pod → Replica Pod: replicates · Database-level replication keeps data in sync
- PostgreSQL → Primary Pod: manages · StatefulSet owns the primary pod identity
- PostgreSQL → Replica Pod: manages · StatefulSet owns replica pod identity
- ConfigMap → Banking API: configures · API receives database and logging settings from config
- Secret → Banking API: credentials · API consumes database credentials from secret
- ConfigMap → PostgreSQL: bootstraps · Init script helps bootstrap PostgreSQL replication/setup
- Autoscaling → Banking API: scales · HPA and VPA tune API replicas and resources
- Policy → Banking API: restricts · RBAC and network policy constrain API access
- Policy → PostgreSQL: restricts · Policy limits database access and pod interactions
- Fluentd → Banking API: collects logs · DaemonSet gathers workload logs cluster-wide
- Fluentd → Dashboard: collects logs · DaemonSet gathers frontend logs cluster-wide
- Fluentd → PostgreSQL: collects logs · DaemonSet gathers database logs cluster-wide
- Setup Script → Ingress: deploys · Automation applies cluster manifests and resources
- Setup Script → Banking API: builds/deploys · Automation builds images and deploys the API
- Setup Script → Dashboard: builds/deploys · Automation builds images and deploys the dashboard
- Setup Script → PostgreSQL: deploys · Automation creates the stateful database tier