> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Alerting (EKS & GKE)

> Deploy Runlayer's operational, audit-pipeline, SIEM export, session-materializer, and database health alerts on self-hosted EKS and GKE clusters

Self-hosted Kubernetes customers own monitoring and alerting for their cluster and external dependencies (see [Shared Responsibility](https://docs.runlayer.com/operations/shared-responsibility.md)). Runlayer maintains two reference Terraform modules (`k8s-alerts/eks` and `k8s-alerts/gke`) that give EKS and GKE deployments operational and security alert coverage aligned with Runlayer's managed ECS fleet:

| Platform | Terraform Module | Backing Services |
| - | - | - |
| **Amazon EKS** | `k8s-alerts/eks` | CloudWatch Logs metric filters + CloudWatch metric alarms |
| **Google GKE** | `k8s-alerts/gke` | Cloud Logging log-based metrics + Cloud Monitoring alert policies |

Both modules read the structured JSON telemetry that Runlayer backend, worker, and consumer pods write to `stdout` (no OTEL collector sidecar or consent flag required). The one exception is database health on EKS, which the worker publishes with `cloudwatch:PutMetricData` (see the IAM permission section below).

> [!NOTE]
>
> The modules are not published to a module registry or download bucket yet. Ask Runlayer Support for the module source that matches your Runlayer release, unpack it next to your Terraform, and point `source` at the unpacked directory (the examples below assume `./modules/k8s-alerts/eks` and `./modules/k8s-alerts/gke`).

Each module also creates a heartbeat alarm per component group that pages when its timer-driven signal stops: `audit-spool-no-data` (the API spool tailer reports `SpoolOldestAgeSeconds` every 10 seconds, even when idle) and `db-health-no-data` (the worker's database health job runs every 15 minutes). A heartbeat page means the telemetry path broke (log shipping, metric filters, IAM, `LOG_LEVEL`), so the other alarms in that group cannot see problems until it clears.

## Amazon EKS (`k8s-alerts/eks`)

### Why metric filters are required on EKS

Runlayer pods write single-line CloudWatch Embedded Metric Format (EMF) JSON to `stdout`. On EKS with the default `amazon-cloudwatch-observability` add-on (Fluent Bit), container `stdout` JSON is nested inside a `log_processed` field:

```json theme={null}
{
  "stream": "stdout",
  "log": "{...}",
  "log_processed": {
    "ExportOrganizations": 2,
    "CustomerId": "acme.runlayer.com",
    "ReaderScope": "bucket",
    "_aws": {
      "CloudWatchMetrics": [{ "Namespace": "Runlayer/AuditLogSiemExport" }]
    }
  }
}
```

Because `_aws` is nested under `log_processed` instead of top-level, CloudWatch Logs does **not** extract EMF metrics automatically. By default (`create_metric_filters = true`), the EKS module creates `aws_cloudwatch_log_metric_filter` resources that extract `$.log_processed.*` into the exact `Runlayer/*` namespaces and dimension schemas expected by the alarms.

> [!NOTE]
>
> If your cluster uses a custom log shipper that emits raw top-level EMF into CloudWatch Logs, set `create_metric_filters = false` to avoid double-counting.

### Terraform example (EKS)

```hcl theme={null}
module "runlayer_eks_alerts" {
  source = "./modules/k8s-alerts/eks" # module source from Runlayer Support

  customer_id    = "acme.runlayer.com" # Must match CUSTOMER_ID on your RunlayerInstance
  name_prefix    = "runlayer-prod"
  log_group_name = "/aws/containerinsights/acme-eks/application"
  alarm_actions  = [aws_sns_topic.runlayer_alerts.arn]

  # Enable groups matching the components enabled on your RunlayerInstance
  enable_audit_log_alarms            = true
  enable_audit_spool_alarms          = true
  enable_audit_consumer_alarms       = true
  enable_siem_export_alarms          = true
  enable_session_materializer_alarms = true
  enable_db_health_alarms            = true

  # Optional AWS native-metric alarms
  audit_log_kinesis_stream_name   = "acme-audit-logs"
  audit_log_kinesis_consumer_name = "acme-audit-consumer"
  rds_cluster_identifier          = "acme-runlayer-aurora"
}
```

### Shared multi-tenant EKS clusters

CloudWatch Logs caps each log group at 100 metric filters. On a shared multi-tenant EKS cluster where multiple `RunlayerInstance` tenants log to the same `/aws/containerinsights/<cluster>/application` log group:

1. Deploy **one** cluster-wide filter-only module instance with `create_metric_filters = true`, `scope_metric_filters_to_customer_id = false`, and `create_alarms = false` (enabling the union of component flags used on the cluster). Its filters emit metrics keyed dynamically by `$.log_processed.CustomerId`.
2. Set `create_metric_filters = false` and a distinct `name_prefix` (for example the tenant name) on **every** per-tenant alarm module instance targeting that cluster, since alarm names are `<name_prefix>-<alarm>` and must be unique per account and region, and enable the optional component flags (for example `enable_siem_export_alarms`, `enable_audit_consumer_alarms`, `enable_session_materializer_alarms`) matching the components that tenant runs—optional flags default to `false` on tenant instances too. Leaving `create_metric_filters = true` on tenant instances alongside an unscoped filter instance publishes every matching log event twice and double-counts `Sum`/`SampleCount` metrics.

### IAM permission for `enable_db_health_alarms` on EKS

Database health signals (`InvalidIndexCount`, `AuditlogDefaultPartitionRows`, `PartmanMaintenanceFailedRuns`, `PartmanRunwayDays`) are published by the worker via `cloudwatch:PutMetricData` rather than stdout EMF. Grant your worker IRSA role permission scoped to the `Runlayer/DatabaseHealth` namespace:

```json theme={null}
{
  "Effect": "Allow",
  "Action": "cloudwatch:PutMetricData",
  "Resource": "*",
  "Condition": {
    "StringEquals": {
      "cloudwatch:namespace": "Runlayer/DatabaseHealth"
    }
  }
}
```

## Google GKE (`k8s-alerts/gke`)

GKE's Cloud Logging agent parses single-line `stdout` JSON directly into `jsonPayload`. The GKE module creates Cloud Logging user-defined metrics (`google_logging_metric`) scoped to your cluster, namespace, and `CUSTOMER_ID`, paired with `google_monitoring_alert_policy` resources.

* **Database health on GKE**: the worker logs `db_health_metrics_completed` at `INFO` level with `invalid_index_count`, `auditlog_default_rows`, `partman_failed_runs`, and `partman_runway_days` on every 15-minute run even without AWS credentials, so `enable_db_health_alarms = true` works natively from Cloud Logging. Keep the worker at `LOG_LEVEL=INFO` (or `DEBUG`)—setting `LOG_LEVEL=WARNING` or higher suppresses `db_health_metrics_completed` and silences all four GKE database-health policies (`db-health-no-data` then pages). Unlike the fleet's consecutive-period alarms, GKE counts breaching runs in a single jitter-tolerant window (`2100s` for 2 runs / `3000s` for 3 runs) so 1s of cron jitter cannot reset the alert; this intentionally also pages on intermittent failures within that window (for example `1, 0, 1` at minutes `0, 15, 30`).
* **SIEM export on GKE**: `audit-log-siem-export-failed` alerts on `gcs_upload`, `export_prepare`, `dead_letter`, and `organization_pin` faults, `audit-log-siem-export-orgrec` alerts hourly on `organization_record` faults, and `audit-log-siem-export-dead-letters` alerts on per-record `validate` and `enrich` dead letters.
* **Confirming heartbeats armed on GKE**: Cloud Monitoring only arms metric-absence policies (`condition_absent`) after the backing metric writes at least one point following policy creation or modification—unlike EKS (`treat_missing_data = "breaching"`), a misconfigured `cluster_name`, `namespace_name`, or `customer_id` filter will leave a heartbeat unarmed instead of paging. After applying or modifying the module, check Cloud Monitoring Metrics Explorer and confirm both `logging.googleapis.com/user/<name_prefix>-audit-spool-no-data` and `logging.googleapis.com/user/<name_prefix>-db-health-no-data` (allow up to 15 minutes for the first worker run) report datapoints.

### Terraform example (GKE)

```hcl theme={null}
module "runlayer_gke_alerts" {
  source = "./modules/k8s-alerts/gke" # module source from Runlayer Support

  project_id            = "acme-prod-123456"
  cluster_name          = "acme-runlayer-gke"
  namespace_name        = "runlayer"
  customer_id           = "acme.runlayer.com" # Must match CUSTOMER_ID on your RunlayerInstance
  name_prefix           = "runlayer-prod"
  notification_channels = [google_monitoring_notification_channel.pagerduty.name]

  # Enable groups matching the components enabled on your RunlayerInstance
  enable_audit_log_alarms            = true
  enable_audit_spool_alarms          = true
  enable_audit_consumer_alarms       = true
  enable_siem_export_alarms          = true
  enable_session_materializer_alarms = true
  enable_db_health_alarms            = true

  # Optional GCP native-metric alerts
  audit_log_pubsub_subscription_id            = "runlayer-audit-logs-sub"
  session_materializer_pubsub_subscription_id = "runlayer-hook-events-sub"
  cloudsql_database_id                        = "acme-prod-123456:runlayer-pg"
}
```

## Alert coverage by component flag

| Terraform Variable | Default | Alerts Covered |
| - | - | - |
| `enable_audit_log_alarms` | `true` | Emit failures (`> 5/min` for 5m), end-to-end latency (`> 60s` for 15m), sustained inline fallback (`15m`), reserved offload-marker probe (`ReservedMarkerEscaped`) |
| `enable_audit_spool_alarms` | `true` | Dead-letter prune loss (`SpoolDeadPruned`, `Rollup = true`), shutdown undrained, uncounted dead prune, dead-letter write failure, backlog age (`> 5m`), sustained spool fallback (`15m`, `Rollup = true`), spool heartbeat absence (`15m`) |
| `enable_audit_consumer_alarms` | `false` | Audit persistence consumer dead letters (`KinesisDeadLetter` on Kinesis and `Target=gcp_pubsub` on Pub/Sub) |
| `enable_siem_export_alarms` | `false` | SIEM export failures (`ExportFailed` excl. `validate`/`enrich`/`organization_record`), organization-record failures (`audit-log-siem-export-orgrec`), SIEM export dead letters, multi-org shared-readers exposure (`ExportOrganizations > 1` with `ReaderScope=bucket`), multi-org batch split (`MultiOrgBatch > 0` with `ReaderScope=bucket`), foreign payload ref probe (`ForeignObjectRefSkipped`) |
| `enable_session_materializer_alarms` | `false` | Compaction backlog age (`> 30h` for 30m), new quarantine entry (`CompactionQuarantineEntered`), plus ingest lag (`MillisBehindLatest` > 5m for 15m), heartbeat absence, and Kinesis dead letters (`KinesisDeadLetter`) on EKS, or Pub/Sub dead letters (`GcpPubsubDeadLetter`) on GKE |
| `enable_session_siem_export_alarms` | `false` | Session SIEM export failures (`Runlayer/SessionSiemExport` `ExportFailed`; EKS only) |
| `enable_agent_event_trigger_alarms` | `false` | Agent event-trigger dead letters (`Runlayer/AgentEventTriggers` `KinesisDeadLetter`; EKS only) |
| `enable_audit_archive_alarms` | `false` | Archive lag (`>= 2 days`), archive failures, and archive verification drift (EKS only) |
| `enable_db_health_alarms` | `false` | Invalid PostgreSQL indexes (`45m`), `auditlog` DEFAULT partition rows (`30m`), `pg_cron` partman failures (`30m`), partition runway `< 14 days` (`30m`), database health heartbeat absence (`1h`) |
| Native stream & DB variables | `null` | Kinesis EFO consumer lag (`SubscribeToShardEvent.MillisBehindLatest`) / Pub/Sub oldest unacked message age (`> 5m` for 10m), Aurora writer CPU / Cloud SQL CPU (`> 85%` for 15m) |

> [!NOTE]
>
> **Minimum backend release for spool loss and fallback alarms:** `audit-spool-dead-letters-pruned` (`SpoolDeadPruned`) and `audit-spool-fallback-sustained` (`SpoolFallback`) filter on the backend emitter's top-level `Rollup: true` EMF property so excluded reasons (such as `retention_exported` and `spool_closed`) stay owned by the backend. Both alarms need a backend image that emits `Rollup: true`, which ships in the same Runlayer release as these modules: use the module source Support gives you for your release, and ask Support if you are unsure whether your backend image is new enough. Against older backend images that do not emit `Rollup`, those two filters match no events and their `notBreaching` alarms stay silent even while every other alarm in the module functions normally.

## Multi-org SIEM export reader scope (`ReaderScope`)

When `components.siemExport.enabled` is `true`, the Runlayer Operator automatically sets `AUDIT_LOG_SIEM_EXPORT_DEPLOYED=true` on the worker so `ExportOrganizations` is emitted hourly. By default, `AUDIT_LOG_SIEM_EXPORT_READER_SCOPE` is unset and reports `ReaderScope=bucket`, which causes `audit-log-siem-export-multi-org-shared-readers` and `audit-log-siem-export-multi-org-batch-shared-readers` to alert whenever more than one organization exports into the same bucket.

To clear those alarms on a multi-org deployment:

1. Either pin export to a single organization via `AUDIT_LOG_SIEM_EXPORT_ORGANIZATION_ID`, **or**
2. Switch `AUDIT_LOG_SIEM_EXPORT_KEY_LAYOUT=org_partitioned`, verify every S3/GCS reader is restricted to a single `organization_id=<uuid>/` prefix (never the bucket root), and then set `AUDIT_LOG_SIEM_EXPORT_READER_SCOPE=organization` via `spec.extraEnv` on your `RunlayerInstance`.

## Related docs

> [card] [Operator deployment guide](https://docs.runlayer.com/deployment/runlayer-operator.md)
>
> Install the Runlayer Operator and configure components

> [card] [Monitoring](https://docs.runlayer.com/infrastructure/monitoring)
>
> Platform observability and alerting overview

> [card] [Shared responsibility](https://docs.runlayer.com/operations/shared-responsibility.md)
>
> Operational ownership split for self-hosted deployments

> [card] [Workload identity](https://docs.runlayer.com/deployment/workload-identity.md)
>
> IRSA and GKE Workload Identity permissions


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.