# Send Kubernetes Error Logs to Splunk

When API7 Gateway runs on Kubernetes, its error logs are emitted by the gateway containers and collected at the platform level. This is different from route-level access-log streaming with logger plugins such as [`splunk-hec-logging`](https://docs.api7.ai/hub/splunk-hec-logging.md).

Use this guide when you want to collect gateway **error logs** from Kubernetes pods and forward them to Splunk for centralized troubleshooting.

This workflow specializes the container-output model described in [Collect Gateway Logs on Kubernetes](https://docs.api7.ai/api7-gateway/observability/kubernetes-log-collection.md). Review that guide first when you need to compare container output with files in the pod or use a backend other than Splunk.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before you begin, ensure you have:

* API7 Gateway data plane pods are running on Kubernetes.
* You have access to a Splunk deployment, either Splunk Cloud or self-managed Splunk.
* You can install a Helm chart into the Kubernetes cluster.
* You have permission to create or use an HTTP Event Collector (HEC) token in Splunk.

## Step 1: Prepare Splunk[​](#step-1-prepare-splunk "Direct link to Step 1: Prepare Splunk")

If you already have Splunk and an HEC token, continue to [Step 2](#step-2-create-a-splunk-index).

For a local test environment, you can run Splunk on the host with Docker Compose:

docker-compose.yaml

```
services:

  splunk:

    image: splunk/splunk:9.2

    container_name: splunk

    hostname: splunk

    environment:

      - SPLUNK_START_ARGS=--accept-license

      - SPLUNK_PASSWORD=yourpassword123

      - SPLUNK_HEC_TOKEN=your-hec-token

    ports:

      - "8000:8000"

      - "8088:8088"

      - "8089:8089"

    healthcheck:

      test: ["CMD", "curl", "-f", "http://localhost:8000"]

      interval: 30s

      timeout: 10s

      retries: 3

    restart: unless-stopped
```

Start Splunk:

```
docker compose up -d
```

note

The collector runs inside Kubernetes, so the HEC endpoint must be reachable from collector pods. For a host-side Docker Compose deployment, use a host name or IP that your cluster can resolve and reach. In a local kind-based setup, `host.docker.internal` works.

## Step 2: Create a Splunk Index[​](#step-2-create-a-splunk-index "Direct link to Step 2: Create a Splunk Index")

Create a dedicated index for gateway error logs so searches and retention can be managed separately from access logs.

For example, create an index named `gateway_error_logs`.

## Step 3: Create a Splunk HEC Token[​](#step-3-create-a-splunk-hec-token "Direct link to Step 3: Create a Splunk HEC Token")

In Splunk:

1. Go to **Settings > Data Inputs > HTTP Event Collector**.
2. Create a new token.
3. Record the HEC token value.

The HEC endpoint URL is typically:

```
https://<SPLUNK_HOST>:8088/services/collector/event
```

If you use the Docker Compose example above with a local kind cluster, set `SPLUNK_HOST` to `host.docker.internal`.

## Step 4: Install the Splunk OpenTelemetry Collector[​](#step-4-install-the-splunk-opentelemetry-collector "Direct link to Step 4: Install the Splunk OpenTelemetry Collector")

Install the Splunk OpenTelemetry Collector for Kubernetes and configure it to collect container logs.

This example enables log collection only, disables metrics and traces, and forwards entries to the `gateway_error_logs` index.

Create a values file such as the following:

values.yaml

```
clusterName: "my-cluster"



splunkPlatform:

  endpoint: "https://<SPLUNK_HOST>:8088/services/collector/event"

  token: "your-hec-token"

  index: "gateway_error_logs"

  insecureSkipVerify: true



  logsEnabled: true

  metricsEnabled: false

  tracesEnabled: false



logsCollection:

  containers:

    enabled: true

    excludeAgentLogs: true

    extraOperators:

      - type: "filter"

        expr: 'resource["k8s.container.name"] != "gateway"'

      - type: "filter"

        expr: 'attributes["log.iostream"] != "stderr"'



agent:

  resources:

    limits:

      cpu: 1

      memory: 512Mi

    requests:

      cpu: 200m

      memory: 256Mi
```

❶ Keep only API7 Gateway container logs so the collector does not forward error-like entries from other Kubernetes workloads on the same node.

❷ Keep the standard-error stream, which carries the gateway error log in the official images. Filtering by message keywords can discard valid `warn`, `crit`, `alert`, or `emerg` entries and can retain an access log whose request text happens to contain the keyword.

Adjust the first filter if your gateway container uses a different name. If you configure the gateway to write regular files instead of the standard streams, collect those files as described in [Collect Gateway Logs on Kubernetes](https://docs.api7.ai/api7-gateway/observability/kubernetes-log-collection.md).

Install the collector:

```
helm repo add splunk-otel-collector https://signalfx.github.io/splunk-otel-collector-chart

helm repo update

helm upgrade --install my-splunk-otel-collector \

  -n logging \

  --create-namespace \

  -f values.yaml \

  splunk-otel-collector/splunk-otel-collector
```

For advanced configuration options, see the [Splunk OpenTelemetry Collector Helm chart values reference](https://github.com/signalfx/splunk-otel-collector-chart/blob/main/helm-charts/splunk-otel-collector/values.yaml).

## Step 5: Verify Log Collection[​](#step-5-verify-log-collection "Direct link to Step 5: Verify Log Collection")

Generate or wait for an error from an API7 Gateway pod, then search Splunk for matching events.

For example:

```
index="gateway_error_logs" sourcetype="kube:container:gateway"
```

You should see standard-error entries from API7 Gateway containers in the configured index.

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

* Verify that the collector pods are running and healthy in the `logging` namespace.
* Confirm the HEC endpoint URL and token are correct.
* If Splunk runs outside the cluster, verify that the HEC host is reachable from collector pods, not just from your local shell.
* Check whether the filter expression is excluding too much data.
* Make sure the API7 Gateway pods are writing logs to container output that the collector can read.
* If Splunk uses a trusted certificate, replace `insecureSkipVerify: true` with the appropriate TLS configuration for production.

## Next Steps[​](#next-steps "Direct link to Next Steps")

* [Collect Gateway Logs on Kubernetes](https://docs.api7.ai/api7-gateway/observability/kubernetes-log-collection.md) — compare container output and files in the pod, with examples for the OpenTelemetry Collector and Filebeat.
* [Configure Centralized Logging](https://docs.api7.ai/api7-gateway/observability/logging.md) — compare file shipping, collector-based shipping, and plugin-based logging.
* [Send Access Logs to Splunk](https://docs.api7.ai/api7-gateway/observability/splunk-integration.md) — send access logs directly from the gateway.
* [Configure Distributed Tracing](https://docs.api7.ai/api7-gateway/observability/tracing.md) — correlate runtime failures with traces when request-level visibility is needed.
