Managed Nginx Caching Service

The Nginx-based HTTP caching service is designed to optimize web traffic and enhance web application performance. This service combines custom-built Nginx instances with HAProxy for efficient caching and load balancing.

Deployment information

The Nginx instances include the following modules and features:

  • VTS module for statistics
  • Integration with ip2location
  • Integration with ip2proxy
  • Support for 51Degrees
  • Cache purge functionality

HAproxy plays a vital role in this setup by directing incoming traffic to specific Nginx instances based on a consistent hash calculated from the URL. Each Nginx instance includes a Persistent Volume Claim (PVC) for storing cached content, ensuring fast and reliable access to frequently used resources.

Deployment Details

The deployment architecture is illustrated in the diagram below:


          ┌─────────┐
          │ metallb │ arp announce
          └────┬────┘
               │
               │
       ┌───────▼───────────────────────────┐
       │  kubernetes service               │  node
       │ (externalTrafficPolicy: Local)    │  level
       └──────────┬────────────────────────┘
                  │
                  │
             ┌────▼────┐  ┌─────────┐
             │ haproxy │  │ haproxy │   loadbalancer
             │ (active)│  │ (backup)│      layer
             └────┬────┘  └─────────┘
                  │
                  │ balance uri whole
                  │ hash-type consistent
           ┌──────┴──────┬──────────────┐
       ┌───▼───┐     ┌───▼───┐      ┌───▼───┐ caching
       │ nginx │     │ nginx │      │ nginx │  layer
       └───┬───┘     └───┬───┘      └───┬───┘
           │             │              │
      ┌────┴───────┬─────┴────┬─────────┴──┐
      │            │          │            │
  ┌───▼────┐  ┌────▼───┐  ┌───▼────┐  ┌────▼───┐
  │ origin │  │ origin │  │ origin │  │ origin │
  └────────┘  └────────┘  └────────┘  └────────┘

Known issues

Parameters

Common parameters

NameDescriptionValue
externalEnable external access from outside the clusterfalse
sizePersistent Volume size10Gi
storageClassStorageClass used to store the data""
haproxy.replicasNumber of HAProxy replicas2
nginx.replicasNumber of Nginx replicas2
haproxy.resourcesExplicit CPU and memory configuration for each HAProxy replica. When left empty, the preset defined in resourcesPreset is applied.{}
haproxy.resourcesPresetDefault sizing preset used when resources is omitted. Allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge.nano
nginx.resourcesExplicit CPU and memory configuration for each nginx replica. When left empty, the preset defined in resourcesPreset is applied.{}
nginx.resourcesPresetDefault sizing preset used when resources is omitted. Allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge.nano

Configuration parameters

NameDescriptionValue
endpointsEndpoints configuration[]

Parameter examples and reference

resources and resourcesPreset

resources sets explicit CPU and memory configurations for each replica. When left empty, the preset defined in resourcesPreset is applied.

resources:
  cpu: 4000m
  memory: 4Gi

resourcePreset sets named CPU and memory configurations for each replica. This setting is ignored if the corresponding resources value is set.

Preset nameCPUmemory
nano100m128Mi
micro250m256Mi
small500m512Mi
medium500m1Gi
large12Gi
xlarge24Gi
2xlarge48Gi

endpoints

endpoints is a flat list of IP addresses:

endpoints:
  - 10.100.3.1:80
  - 10.100.3.11:80
  - 10.100.3.2:80
  - 10.100.3.12:80
  - 10.100.3.3:80
  - 10.100.3.13:80