Cortex
Horizontally scalable, multi-tenant Prometheus service.
Overview
Cortex is a horizontally scalable, multi-tenant Prometheus implementation designed to provide long-term storage and high availability for metrics data. Originally developed by Grafana Labs (now in maintenance mode with development shifted to Grafana Mimir), Cortex addresses Prometheus's limitations around scalability and multi-tenancy by providing a distributed architecture that can handle massive metric ingestion rates while maintaining complete Prometheus API compatibility.
This deployment creates a minimal Cortex cluster using two essential services: the Cortex service itself configured for distributed operation, and HashiCorp Consul providing service discovery and coordination between Cortex components. The Cortex container runs multiple internal microservices (distributor, ingester, querier, query-frontend) within a single process, while Consul handles the cluster membership and health checking required for proper distributed operation.
This configuration is ideal for organizations running multiple Prometheus instances who need centralized, scalable metrics storage with tenant isolation. Platform teams managing metrics infrastructure across multiple environments will find this setup valuable for consolidating monitoring data while maintaining organizational boundaries through Cortex's multi-tenant capabilities.
Key Features
- Multi-tenant metrics ingestion with X-Scope-OrgID header-based tenant isolation
- Prometheus remote_write compatibility for direct integration with existing Prometheus deployments
- Consul-based service discovery enabling automatic cluster member coordination and health monitoring
- Horizontal scalability through Cortex's microservices architecture running in single-process mode
- Long-term metrics storage with configurable retention policies and downsampling
- Complete Prometheus Query API compatibility for integration with Grafana and other visualization tools
- Built-in load balancing and high availability through Consul's distributed consensus
- Configurable ingestion limits and rate limiting per tenant for resource protection
Common Use Cases
- 1Centralized metrics storage for multiple Kubernetes clusters each running Prometheus
- 2Multi-tenant SaaS platforms requiring isolated metrics collection per customer organization
- 3Enterprise monitoring consolidation where different teams need separate metric namespaces
- 4Long-term metrics retention beyond single Prometheus instance storage limitations
- 5High-availability Prometheus replacement for mission-critical monitoring infrastructure
- 6Development and staging environment metrics aggregation with production data separation
- 7Managed service providers offering Prometheus-as-a-Service to multiple clients
Prerequisites
- Minimum 1GB RAM available (512MB for Cortex + 256MB for Consul + system overhead)
- Docker host with ports 8500 and 9009 available for Consul UI and Cortex API access
- Valid cortex/config.yaml file configured with storage backend and cluster settings
- Understanding of Prometheus remote_write configuration for metric forwarding
- Familiarity with multi-tenant concepts and HTTP header-based tenant routing
- Basic knowledge of YAML configuration for Cortex microservices tuning
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 consul: 3 image: consul:latest4 container_name: consul5 ports: 6 - "8500:8500"7 networks: 8 - cortex-network910 cortex: 11 image: cortexproject/cortex:latest12 container_name: cortex13 command: 14 - -config.file=/etc/cortex/config.yaml15 volumes: 16 - ./cortex/config.yaml:/etc/cortex/config.yaml:ro17 - cortex_data:/data18 ports: 19 - "9009:9009"20 depends_on: 21 - consul22 networks: 23 - cortex-network2425volumes: 26 cortex_data: 2728networks: 29 cortex-network: 30 driver: bridge.env Template
.env
1# Cortex configuration file requiredUsage Notes
- 1Docs: https://cortexmetrics.io/docs/
- 2Prometheus remote_write endpoint: http://localhost:9009/api/v1/push
- 3Create cortex/config.yaml before starting
- 4Multi-tenant: set X-Scope-OrgID header for tenant isolation
- 5Consul provides service discovery for cluster coordination
- 6Note: Project is in maintenance mode, consider Mimir for new deployments
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
consul
consul:
image: consul:latest
container_name: consul
ports:
- "8500:8500"
networks:
- cortex-network
cortex
cortex:
image: cortexproject/cortex:latest
container_name: cortex
command:
- "-config.file=/etc/cortex/config.yaml"
volumes:
- ./cortex/config.yaml:/etc/cortex/config.yaml:ro
- cortex_data:/data
ports:
- "9009:9009"
depends_on:
- consul
networks:
- cortex-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 consul:5 image: consul:latest6 container_name: consul7 ports:8 - "8500:8500"9 networks:10 - cortex-network1112 cortex:13 image: cortexproject/cortex:latest14 container_name: cortex15 command:16 - -config.file=/etc/cortex/config.yaml17 volumes:18 - ./cortex/config.yaml:/etc/cortex/config.yaml:ro19 - cortex_data:/data20 ports:21 - "9009:9009"22 depends_on:23 - consul24 networks:25 - cortex-network2627volumes:28 cortex_data:2930networks:31 cortex-network:32 driver: bridge33EOF3435# 2. Create the .env file36cat > .env << 'EOF'37# Cortex configuration file required38EOF3940# 3. Start the services41docker compose up -d4243# 4. View logs44docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/cortex/run | bashTroubleshooting
- Cortex fails to start with config error: Verify cortex/config.yaml exists and contains valid YAML with required storage_config section
- Consul shows unhealthy service checks: Check cortex container logs for HTTP endpoint availability and ensure 9009 port binding is successful
- Remote write from Prometheus fails with 400 error: Confirm X-Scope-OrgID header is set in Prometheus remote_write configuration
- Cortex reports 'no healthy instances' errors: Verify Consul agent is running and accessible, check network connectivity between cortex and consul containers
- Query API returns empty results: Check tenant ID consistency between ingestion and query requests, verify metrics are being successfully written
- High memory usage in cortex container: Review ingestion rate limits and consider adjusting max_concurrent queries in config.yaml
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
cortexconsulminio
Tags
#cortex#prometheus#multi-tenant#scalable#metrics
Category
Monitoring & ObservabilityAd Space
Shortcuts: C CopyF FavoriteD Download