Skip to content

[receiver/k8scluster] Collect k8s.container metrics for sidecars #42571

@r-asiebert

Description

@r-asiebert

Component(s)

receiver/k8scluster

Is your feature request related to a problem? Please describe.

The k8sclusterreceiver doesn't collect metrics for sidecar containers, only for the main containers in a pod:

for _, c := range pod.Spec.Containers {
container.RecordSpecMetrics(logger, mb, c, pod, ts)
}

Describe the solution you'd like

This OtelCol receiver could also collect telemetry from sidecar containers e.g. status, restarts, requests, limits.

Sidecar containers became generally available in Kubernetes 1.29 as special init containers defining a restartPolicy.
Example from the sidecar doc:

apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      containers:
        ...
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt

Main and init containers are sharing the same spec (with restartPolicy only applicable to init containers), so we can likely reuse the existing container telemetry processing code as-is for sidecars.

Init containers are typically meant to be short-lived and were likely excluded for that reason. Only sidecars should be picked up when processing spec.initContainers.

Describe alternatives you've considered

No response

Additional context

Official sidecar containers are:

  • available since Kubernetes 1.28 (EOL Oct 2024),
  • enabled by default since 1.29 (EOL Feb 2025) and
  • stable as of 1.33 (May 2025).

Sidecar containers are the secondary containers that run along with the main application container within the same Pod. These containers are used to enhance or to extend the functionality of the primary app container by providing additional services, or functionality such as logging, monitoring, security, or data synchronization, without directly altering the primary application code.

These containers live as long as the main container(s) of the pod, and as a workaround, used to be implemented as main containers with lifecycle hooks.

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnever staleIssues marked with this label will be never staled and automatically removedpriority:p2Mediumreceiver/k8scluster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions