For the complete documentation index, see llms.txt. This page is also available as Markdown.

Monitor CI pod events without CloudWatch

Use a DaemonSet to monitor and persist CI pod events for debugging OOM kills and pod evictions when CloudWatch is not available.

If your Kubernetes cluster doesn't use monitoring products like CloudWatch, you can deploy a DaemonSet to read and upload CI pod event logs to a storage bucket. This solution helps with:

  • Root cause analysis of resource issues such as OOM (Out of Memory) kills

  • Understanding pod evictions and why they happen in CI pods

  • Debugging with persisted logs for older pipeline executions

Prerequisites

Before implementing this monitoring solution, ensure you have:

  • A storage bucket configured (GCP Cloud Storage, AWS S3, or Azure Blob Storage)

  • Kubernetes service account with appropriate read permissions for pods and events

  • Write access to your storage bucket from the Kubernetes cluster

  • kubectl access to deploy resources to your cluster

Implementation

The monitoring solution consists of three Kubernetes resources that work together to capture and persist CI pod events:

1. ServiceAccount with RBAC permissions

Create a ServiceAccount that can read pods and events across all namespaces:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: ci-pod-monitor-sa
  namespace: harness-delegate-ng
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: ci-pod-monitor-role
rules:
- apiGroups: [""]
  resources: ["pods", "pods/log", "events"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: ci-pod-monitor-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: ci-pod-monitor-role
subjects:
- kind: ServiceAccount
  name: ci-pod-monitor-sa
  namespace: harness-delegate-ng

2. ConfigMap for cloud provider settings

Configure your cloud storage provider and bucket details:

3. ConfigMap with monitoring script

The monitoring script runs four parallel functions to capture comprehensive CI pod information:

4. DaemonSet deployment

Deploy the DaemonSet to run the monitoring script on every node:

Deployment steps

  1. Save all the YAML configurations above into a single file named ci-monitoring.yaml

  2. Update the cloud provider configuration in the ConfigMap:

    • Set provider to your cloud provider (gcp, aws, or azure)

    • Set bucket to your actual bucket name

  3. Apply the configuration to your cluster:

  1. Verify the DaemonSet is running:

What gets captured

The monitoring solution captures four types of data:

  1. Pod logs: Continuous streaming of logs from all CI pods (pods starting with "harnessci")

  2. Kubernetes events: Cluster-wide events captured every 30 seconds, including:

    • Pod scheduling events

    • Container state changes

    • Resource allocation issues

    • Pod evictions

  3. Pod descriptions: Complete kubectl describe output for each CI pod, including:

    • Resource requests and limits

    • Node allocation

    • Container statuses

    • Recent events

  4. Timestamps: All captured data includes timestamps for correlation

Debugging common issues

Identifying OOM kills

Look for these patterns in the pod description files:

In the events files, search for:

Understanding pod evictions

Check the events files for eviction reasons:

Resource pressure indicators

In pod descriptions, look for:

Customization options

Adjust collection intervals

Modify these variables in the script ConfigMap:

  • CLOUD_SYNC_INTERVAL: How often to upload logs to cloud storage (default: 60 seconds)

  • Event collection interval: Change sleep 30 in collect_events() function

  • Pod description interval: Change sleep 60 in log_pod_description() function

Filter different pod patterns

Change the FILTER variable to monitor different pod prefixes:

Add AWS S3 or Azure Blob support

For AWS S3, ensure the nodes have appropriate IAM roles or update the script to include AWS credentials.

For Azure Blob Storage, update the sync command in the script:

Monitoring and maintenance

Check DaemonSet health

View collected data

Check your storage bucket for:

  • Log files: namespace_podname.log

  • Event snapshots: events_YYYYMMDD-HHMMSS.txt

  • Pod descriptions: namespace_podname_describe.txt

Clean up old data

Implement a lifecycle policy on your storage bucket to automatically delete old logs after a retention period (e.g., 30 days).

Troubleshooting the monitoring solution

If the DaemonSet pods are not running:

  1. Check pod status:

  1. Verify ServiceAccount permissions:

  1. Check ConfigMap is properly mounted:

  1. Review container logs for errors:

See also

Last updated

Was this helpful?