Skip to content

Hub Web & API

Overview

Hub is the main application suite consisting of a Blazor web frontend and .NET API backend.

Architecture

graph LR
    subgraph External
        Users[Users]
        CF[Cloudflare]
    end

    subgraph Kubernetes
        subgraph hub namespace
            Web[Hub Web]
            API[Hub API]
        end

        subgraph databases namespace
            Mongo[(MongoDB)]
            Influx[(InfluxDB)]
            ES[(Elasticsearch)]
        end
    end

    Users --> CF
    CF --> Web
    Web --> API
    API --> Mongo
    API --> Influx
    API --> ES

Components

Hub Web

Property Value
Technology Blazor Server
Framework .NET 8
Port 80
URL ajandrews.pro

Hub API

Property Value
Technology ASP.NET Core Web API
Framework .NET 8
Port 8080
URL api.ajandrews.pro

Deployment

Kubernetes Resources

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hub-web
  namespace: hub
spec:
  replicas: 2
  template:
    spec:
      containers:
      - name: hub-web
        image: ajxfear/hub-web:latest
        ports:
        - containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hub-api
  namespace: hub
spec:
  replicas: 2
  template:
    spec:
      containers:
      - name: hub-api
        image: ajxfear/hub-api:latest
        ports:
        - containerPort: 8080

API Endpoints

Weather Service

GET /api/weather/current
GET /api/weather/forecast

Metrics

GET /metrics - Prometheus metrics
GET /health - Health check
GET /ready - Readiness check

Dependencies

Database Connections

Database Purpose
MongoDB Document storage
InfluxDB Time series metrics
Elasticsearch Search and logging

External Services

  • Weather API integration
  • Metrics push to InfluxDB

Configuration

Environment Variables

Variable Description
MONGODB_CONNECTION MongoDB connection string
INFLUXDB_URL InfluxDB endpoint
INFLUXDB_TOKEN InfluxDB auth token
ELASTICSEARCH_URL Elasticsearch endpoint

ConfigMaps

apiVersion: v1
kind: ConfigMap
metadata:
  name: hub-config
  namespace: hub
data:
  ASPNETCORE_ENVIRONMENT: "Production"
  ELASTICSEARCH_URL: "http://elasticsearch.monitoring:9200"

Monitoring

Metrics

The API exposes Prometheus metrics:

Metric Description
http_requests_total Total HTTP requests
http_request_duration_seconds Request latency histogram
hub_weather_requests_total Weather API calls

Health Checks

livenessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 30

readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10

CI/CD Pipeline

GitHub Actions

  1. Push to main branch
  2. Build Docker images
  3. Push to Docker Hub
  4. Update k8s manifests
  5. ArgoCD syncs changes

Image Tags

Tag Description
latest Most recent build
sha-xxxxxx Specific commit

Scaling

Horizontal Pod Autoscaler

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: hub-api
  namespace: hub
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: hub-api
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

Rate Limiting

The API includes rate limiting middleware to prevent abuse:

Limit Value
Per Minute 60 requests
Per Hour 1000 requests

Excluded Endpoints

The following endpoints are excluded from rate limiting to prevent health probe failures:

  • /health - Kubernetes liveness/readiness probes
  • /metrics - Prometheus scraping
  • /ready - Readiness checks
  • /live - Liveness checks

Rate Limit and Health Probes

If health endpoints are not excluded from rate limiting, Kubernetes probes and Prometheus scraping can trigger rate limits, causing pod restart loops.

Troubleshooting

Common Issues

Issue Cause Resolution
502 Bad Gateway Pod not ready Check readiness probe
Slow responses High load Check CPU/memory usage
DB connection failed Network/auth Verify connection string
429 Too Many Requests Rate limit exceeded Wait 60s or check excluded paths
Pod restart loop Health probes rate limited Ensure /health excluded from rate limiting