Skip to main content

K8scluster Receiver

Status Available in: contrib, k8s Maintainers: @dmitryax, @TylerHelmuth, @povilasv, @ChrsMark Source: opentelemetry-collector-contrib

Supported Telemetry

Logs Metrics

Overview

Metrics

Details about the metrics produced by this receiver can be found in metadata.yaml and documentation.md.

Service Metrics (Disabled by default)

The receiver collects service endpoint metrics (k8s.service.endpoint.count) from the discovery.k8s.io EndpointSlice API and LoadBalancer ingress metrics (k8s.service.load_balancer.ingress.count). Note: Enabling endpoint metrics requires additional RBAC permissions for endpointslices in the discovery.k8s.io API group. See the RBAC section for details. Refer to documentation.md for detailed information on these metrics and their semantics.

Configuration

The following settings are required:
  • auth_type (default = serviceAccount): Determines how to authenticate to the K8s API server. This can be one of none (for no auth), serviceAccount (to use the standard service account token provided to the agent pod), or kubeConfig to use credentials from ~/.kube/config.
The following settings are optional:
  • collection_interval (default = 10s): This receiver continuously watches for events using K8s API. However, the metrics collected are emitted only once every collection interval. collection_interval will determine the frequency at which metrics are emitted by this receiver.
  • metadata_collection_interval (default = 5m): Collection interval for metadata for K8s entities such as pods, nodes, etc. Metadata of the particular entity in the cluster is collected when the entity changes. In addition, metadata of all entities is collected periodically even if no changes happen. This setting controls the interval between periodic collections. Setting the duration to 0 will disable periodic collection (however will not impact metadata collection on changes).
  • node_conditions_to_report (default = [Ready]): An array of node conditions this receiver should report. The receiver will emit one metric per entry in the array.
  • distribution (default = kubernetes): The Kubernetes distribution being used by the cluster. Currently supported versions are kubernetes and openshift. Setting the value to openshift enables OpenShift specific metrics in addition to standard kubernetes ones.
  • allocatable_types_to_report (default = []): An array of allocatable resource types this receiver should report. The following allocatable resource types are available (see Node Allocatable in Kubernetes docs):
    • cpu
    • memory
    • ephemeral-storage
    • pods
When enabled, this setting produces the following node-level metrics (one per selected type):
allocatable typemetric nameunittypevalue type
cpuk8s.node.allocatable_cpu{cpu}GaugeDouble
memoryk8s.node.allocatable_memoryByGaugeDouble
ephemeral-storagek8s.node.allocatable_ephemeral_storageByGaugeDouble
podsk8s.node.allocatable_pods{pod}GaugeInt
  • metrics: Allows to enable/disable metrics.
  • resource_attributes: Allows to enable/disable resource attributes.
  • namespace (deprecated, use namespaces instead): Allows to observe resources for a particular namespace only. If this option is set to a non-empty string, Nodes, Namespaces and ClusterResourceQuotas will not be observed.
  • namespaces: Allows to observe resources for a list of given namespaces. If this option is set, Nodes, Namespaces and ClusterResourceQuotas will not be observed, as those are cluster-scoped resources.
Example:
  k8s_cluster:
    auth_type: kubeConfig
    k8s_leader_elector: <reference k8s leader elector extension>
    node_conditions_to_report: [Ready, MemoryPressure]
    allocatable_types_to_report: [cpu, memory]
    metrics:
      k8s.container.cpu_limit:
        enabled: false
    resource_attributes:
      container.id:
        enabled: false
The full list of settings exposed for this receiver are documented in config.go with detailed sample configurations in testdata/config.yaml.

k8s_leader_elector

Provide name of the k8s leader elector extension defined in config. This allows multiple instances of k8s cluster receiver to be executed on a cluster. At a given time only the pod which has the is active.
    k8s_cluster:
        k8s_leader_elector: k8s_leader_elector
...

node_conditions_to_report

For example, with the config below the receiver will emit two metrics k8s.node.condition_ready and k8s.node.condition_memory_pressure, one for each condition in the config. The value will be 1 if the ConditionStatus for the corresponding Condition is True, 0 if it is False and -1 if it is Unknown.
...
k8s_cluster:
  node_conditions_to_report:
    - Ready
    - MemoryPressure
...

metadata_exporters

A list of metadata exporters to which metadata being collected by this receiver should be synced. Exporters specified in this list are expected to implement the following interface. If an exporter that does not implement the interface is listed, startup will fail.
type MetadataExporter interface {
  ConsumeMetadata(metadata []*MetadataUpdate) error
}

type MetadataUpdate struct {
  ResourceIDKey string
  ResourceID    ResourceID
  MetadataDelta
}

type MetadataDelta struct {
  MetadataToAdd    map[string]string
  MetadataToRemove map[string]string
  MetadataToUpdate map[string]string
}
See experimentalmetricmetadata/metadata.go for details about the above types. The same metadata will be also emitted as entity events in the form of log records if this receiver is connected to a logs pipeline. See opentelemetry-collector-contrib#23565 for the format of emitted log records.

Compatibility

Kubernetes Versions

This receiver is tested against the Kubernetes versions specified in the e2e-tests.yml workflow. These tested versions represent the officially supported Kubernetes versions for this component.

Example

Here is an example deployment of the collector that sets up this receiver along with the debug exporter. Follow the below sections to setup various Kubernetes resources required for the deployment.

Configuration

Create a ConfigMap with the config for otelcontribcol:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
data:
  config.yaml: |
    receivers:
      k8s_cluster:
        collection_interval: 10s
    exporters:
      debug:
    service:
      pipelines:
        metrics:
          receivers: [k8s_cluster]
          exporters: [debug]
        logs/entity_events:
          receivers: [k8s_cluster]
          exporters: [debug]
EOF

Service Account

Create a service account that the collector should use.
<<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: otelcontribcol
  name: otelcontribcol
EOF

RBAC

Use the below commands to create a ClusterRole with required permissions and a ClusterRoleBinding to grant the role to the service account created above.
<<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
rules:
- apiGroups:
  - ""
  resources:
  - events
  - namespaces
  - namespaces/status
  - nodes
  - nodes/spec
  - pods
  - pods/status
  - replicationcontrollers
  - replicationcontrollers/status
  - resourcequotas
  - services
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - discovery.k8s.io
  resources:
  - endpointslices
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - apps
  resources:
  - daemonsets
  - deployments
  - replicasets
  - statefulsets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - daemonsets
  - deployments
  - replicasets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - batch
  resources:
  - jobs
  - cronjobs
  verbs:
  - get
  - list
  - watch
- apiGroups:
    - autoscaling
  resources:
    - horizontalpodautoscalers
  verbs:
    - get
    - list
    - watch
EOF
<<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: otelcontribcol
subjects:
- kind: ServiceAccount
  name: otelcontribcol
  namespace: default
EOF
As an alternative to setting up a ClusterRole/ClusterRoleBinding, it is also possible to limit the observed resources to a list of particular namespaces by setting the namespaces option of the receiver. This allows the collector to only rely on Roles/RoleBindings, instead of granting the collector cluster-wide read access to resources. Note however, that in this case the following resources will not be observed by the k8sclusterreceiver:
  • Nodes
  • Namespaces
  • ClusterResourceQuotas
To use this approach, use the commands below to create the required Role and RoleBinding for each of the namespaces the collector should observe:
<<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
  namespace: default
rules:
  - apiGroups:
      - ""
    resources:
      - events
      - pods
      - pods/status
      - replicationcontrollers
      - replicationcontrollers/status
      - resourcequotas
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - discovery.k8s.io
    resources:
      - endpointslices
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps
    resources:
      - daemonsets
      - deployments
      - replicasets
      - statefulsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
    resources:
      - daemonsets
      - deployments
      - replicasets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - batch
    resources:
      - jobs
      - cronjobs
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - autoscaling
    resources:
      - horizontalpodautoscalers
    verbs:
      - get
      - list
      - watch
EOF
<<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: otelcontribcol
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: otelcontribcol
subjects:
  - kind: ServiceAccount
    name: otelcontribcol
    namespace: default
EOF

Deployment

Create a Deployment to deploy the collector.
<<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
spec:
  replicas: 1
  selector:
    matchLabels:
      app: otelcontribcol
  template:
    metadata:
      labels:
        app: otelcontribcol
    spec:
      serviceAccountName: otelcontribcol
      containers:
      - name: otelcontribcol
        image: otel/opentelemetry-collector-contrib
        args: ["--config", "/etc/config/config.yaml"]
        volumeMounts:
        - name: config
          mountPath: /etc/config
        imagePullPolicy: IfNotPresent
      volumes:
        - name: config
          configMap:
            name: otelcontribcol
EOF

OpenShift

You can enable OpenShift support to collect OpenShift specific metrics in addition to the default kubernetes ones. To do this, set the distribution key to openshift. Example:
  k8s_cluster:
    distribution: openshift
Add the following rules to your ClusterRole:
- apiGroups:
  - quota.openshift.io
  resources:
  - clusterresourcequotas
  verbs:
  - get
  - list
  - watch

Metrics

Metric NameDescriptionUnitTypeAttributes
k8s.container.cpu_limitMaximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details{cpu}Gauge
k8s.container.cpu_requestResource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for details{cpu}Gauge
k8s.container.ephemeralstorage_limitMaximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.container.ephemeralstorage_requestResource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.container.memory_limitMaximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.container.memory_requestResource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.container.readyWhether a container has passed its readiness probe (0 for no, 1 for yes)Gauge
k8s.container.restartsHow many times the container has restarted in the recent past. This value is pulled directly from the K8s API and the value can go indefinitely high and be reset to 0 at any time depending on how your kubelet is configured to prune dead containers. It is best to not depend too much on the exact value but rather look at it as either == 0, in which case you can conclude there were no restarts in the recent past, or > 0, in which case you can conclude there were restarts in the recent past, and not try and analyze the value beyond that.{restart}Gauge
k8s.container.status.reasonExperimental metric, may experience breaking changes. Describes the number of K8s containers that are currently in a state for a given reason. All possible container state reasons will be reported at each time interval to avoid missing metrics. Only the value corresponding to the current state reason will be non-zero.{container}UpDownCounterk8s.container.status.reason
k8s.container.status.stateExperimental metric, may experience breaking changes. Describes the number of K8s containers that are currently in a given state. All possible container states will be reported at each time interval to avoid missing metrics. Only the value corresponding to the current state will be non-zero.{container}UpDownCounterk8s.container.status.state
k8s.container.storage_limitMaximum resource limit set for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.container.storage_requestResource requested for the container. See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#resourcerequirements-v1-core for detailsByGauge
k8s.cronjob.active_jobsThe number of actively running jobs for a cronjob{job}Gauge
k8s.daemonset.current_scheduled_nodesNumber of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod{node}Gauge
k8s.daemonset.desired_scheduled_nodesNumber of nodes that should be running the daemon pod (including nodes currently running the daemon pod){node}Gauge
k8s.daemonset.misscheduled_nodesNumber of nodes that are running the daemon pod, but are not supposed to run the daemon pod{node}Gauge
k8s.daemonset.ready_nodesNumber of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready{node}Gauge
k8s.deployment.availableTotal number of available pods (ready for at least minReadySeconds) targeted by this deployment{pod}Gauge
k8s.deployment.desiredNumber of desired pods in this deployment{pod}Gauge
k8s.hpa.current_replicasCurrent number of pod replicas managed by this autoscaler.{pod}Gauge
k8s.hpa.desired_replicasDesired number of pod replicas managed by this autoscaler.{pod}Gauge
k8s.hpa.max_replicasMaximum number of replicas to which the autoscaler can scale up.{pod}Gauge
k8s.hpa.min_replicasMinimum number of replicas to which the autoscaler can scale up.{pod}Gauge
k8s.job.active_podsThe number of actively running pods for a job{pod}Gauge
k8s.job.desired_successful_podsThe desired number of successfully finished pods the job should be run with{pod}Gauge
k8s.job.failed_podsThe number of pods which reached phase Failed for a job{pod}Gauge
k8s.job.max_parallel_podsThe max desired number of pods the job should run at any given time{pod}Gauge
k8s.job.successful_podsThe number of pods which reached phase Succeeded for a job{pod}Gauge
k8s.namespace.phaseThe current phase of namespaces (1 for active and 0 for terminating)Gauge
k8s.node.conditionThe condition of a particular Node.{condition}Gaugecondition
k8s.pod.phaseCurrent phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown)Gauge
k8s.pod.status_reasonCurrent status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4 - Shutdown, 5 - UnexpectedAdmissionError, 6 - Unknown)Gauge
k8s.replicaset.availableTotal number of available pods (ready for at least minReadySeconds) targeted by this replicaset{pod}Gauge
k8s.replicaset.desiredNumber of desired pods in this replicaset{pod}Gauge
k8s.replication_controller.availableTotal number of available pods (ready for at least minReadySeconds) targeted by this replication_controller{pod}Gauge
k8s.replication_controller.desiredNumber of desired pods in this replication_controller{pod}Gauge
k8s.resource_quota.hard_limitThe upper limit for a particular resource in a specific namespace. Will only be sent if a quota is specified. CPU requests/limits will be sent as millicores{resource}Gaugeresource
k8s.resource_quota.usedThe usage for a particular resource in a specific namespace. Will only be sent if a quota is specified. CPU requests/limits will be sent as millicores{resource}Gaugeresource
k8s.service.endpoint.countThe number of endpoints for a service, broken down by condition, address type, and zone.{endpoint}Gaugek8s.service.endpoint.address_type, k8s.service.endpoint.condition, k8s.service.endpoint.zone
k8s.service.load_balancer.ingress.countThe number of load balancer ingress points (external IPs/hostnames) assigned to the service.{ingress}Gauge
k8s.statefulset.current_podsThe number of pods created by the StatefulSet controller from the StatefulSet version{pod}Gauge
k8s.statefulset.desired_podsNumber of desired pods in the stateful set (the spec.replicas field){pod}Gauge
k8s.statefulset.ready_podsNumber of pods created by the stateful set that have the Ready condition{pod}Gauge
k8s.statefulset.updated_podsNumber of pods created by the StatefulSet controller from the StatefulSet version{pod}Gauge
openshift.appliedclusterquota.limitThe upper limit for a particular resource in a specific namespace.{resource}Gaugek8s.namespace.name, resource
openshift.appliedclusterquota.usedThe usage for a particular resource in a specific namespace.{resource}Gaugek8s.namespace.name, resource
openshift.clusterquota.limitThe configured upper limit for a particular resource.{resource}Gaugeresource
openshift.clusterquota.usedThe usage for a particular resource with a configured limit.{resource}Gaugeresource

Attributes

Attribute NameDescriptionTypeValues
conditionthe name of Kubernetes Node condition. Example: Ready, Memory, PID, DiskPressurestring
k8s.container.status.reasonThe reason of the current container status.stringContainerCreating, CrashLoopBackOff, CreateContainerConfigError, ErrImagePull, ImagePullBackOff, OOMKilled, Completed, Error, ContainerCannotRun
k8s.container.status.stateThe state of the container (terminated, running, waiting). See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#containerstate-v1-core for details.stringterminated, running, waiting
k8s.namespace.nameThe k8s namespace name.string
k8s.service.endpoint.address_typeThe address type of the endpoint.stringIPv4, IPv6, FQDN
k8s.service.endpoint.conditionThe condition of the service endpoint.stringready, serving, terminating
k8s.service.endpoint.zoneThe zone of the service endpoint, typically corresponding to a failure domain.string
resourcethe name of the resource on which the quota is appliedstring

Resource Attributes

Attribute NameDescriptionTypeEnabled
container.idThe container id.string
container.image.nameThe container image namestring
container.image.tagThe container image tagstring
container.runtimeThe container runtime used by Kubernetes Node.string
container.runtime.versionThe version of container runtime used by Kubernetes Node.string
k8s.container.nameThe k8s container namestring
k8s.container.status.last_terminated_reasonLast terminated reason of a container.string
k8s.cronjob.nameThe k8s CronJob namestring
k8s.cronjob.uidThe k8s CronJob uid.string
k8s.daemonset.nameThe k8s daemonset name.string
k8s.daemonset.uidThe k8s daemonset uid.string
k8s.deployment.nameThe name of the Deployment.string
k8s.deployment.uidThe UID of the Deployment.string
k8s.hpa.nameThe k8s hpa name.string
k8s.hpa.scaletargetref.apiversionThe API version of the target resource to scale for the HorizontalPodAutoscaler.string
k8s.hpa.scaletargetref.kindThe kind of the target resource to scale for the HorizontalPodAutoscaler.string
k8s.hpa.scaletargetref.nameThe name of the target resource to scale for the HorizontalPodAutoscaler.string
k8s.hpa.uidThe k8s hpa uid.string
k8s.job.nameThe k8s pod name.string
k8s.job.uidThe k8s job uid.string
k8s.kubelet.versionThe version of Kubelet running on the node.string
k8s.namespace.nameThe k8s namespace name.string
k8s.namespace.uidThe k8s namespace uid.string
k8s.node.nameThe k8s node name.string
k8s.node.uidThe k8s node uid.string
k8s.pod.nameThe k8s pod name.string
k8s.pod.qos_classThe k8s pod qos class name. One of Guaranteed, Burstable, BestEffort.string
k8s.pod.uidThe k8s pod uid.string
k8s.replicaset.nameThe k8s replicaset namestring
k8s.replicaset.uidThe k8s replicaset uidstring
k8s.replicationcontroller.nameThe k8s replicationcontroller name.string
k8s.replicationcontroller.uidThe k8s replicationcontroller uid.string
k8s.resourcequota.nameThe k8s resourcequota name.string
k8s.resourcequota.uidThe k8s resourcequota uid.string
k8s.service.nameThe k8s service name.string
k8s.service.publish_not_ready_addressesWhether the Service publishes not-ready endpoints.bool
k8s.service.traffic_distributionThe traffic distribution policy for the Service (e.g., PreferClose).string
k8s.service.typeThe k8s service type.string
k8s.service.uidThe k8s service uid.string
k8s.statefulset.nameThe k8s statefulset name.string
k8s.statefulset.uidThe k8s statefulset uid.string
openshift.clusterquota.nameThe k8s ClusterResourceQuota name.string
openshift.clusterquota.uidThe k8s ClusterResourceQuota uid.string
os.descriptionThe os description used by Kubernetes Node.string
os.typeThe os type used by Kubernetes Node.string

Configuration

Example Configuration

k8s_cluster:
k8s_cluster/all_settings:
  collection_interval: 30s
  node_conditions_to_report: [ "Ready", "MemoryPressure" ]
  allocatable_types_to_report: [ "cpu","memory" ]
  metadata_exporters: [ nop ]
  metadata_collection_interval: 30m
k8s_cluster/partial_settings:
  collection_interval: 30s
  distribution: openshift

Last generated: 2026-04-13