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
kubectlaccess 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-ng2. 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
Save all the YAML configurations above into a single file named
ci-monitoring.yamlUpdate the cloud provider configuration in the ConfigMap:
Set
providerto your cloud provider (gcp,aws, orazure)Set
bucketto your actual bucket name
Apply the configuration to your cluster:
Verify the DaemonSet is running:
What gets captured
The monitoring solution captures four types of data:
Pod logs: Continuous streaming of logs from all CI pods (pods starting with "harnessci")
Kubernetes events: Cluster-wide events captured every 30 seconds, including:
Pod scheduling events
Container state changes
Resource allocation issues
Pod evictions
Pod descriptions: Complete
kubectl describeoutput for each CI pod, including:Resource requests and limits
Node allocation
Container statuses
Recent events
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 30incollect_events()functionPod description interval: Change
sleep 60inlog_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.logEvent snapshots:
events_YYYYMMDD-HHMMSS.txtPod 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:
Check pod status:
Verify ServiceAccount permissions:
Check ConfigMap is properly mounted:
Review container logs for errors:
See also
Last updated
Was this helpful?