> ## Documentation Index
> Fetch the complete documentation index at: https://otel.fyi/llms.txt
> Use this file to discover all available pages before exploring further.

# K8sleaderelector

> OpenTelemetry extension for K8sleaderelector

# K8sleaderelector Extension

![Status](https://img.shields.io/badge/status-alpha-red)

**Available in:** `contrib`, `k8s`

**Maintainers:** [@dmitryax](https://github.com/dmitryax), [@rakesh-garimella](https://github.com/rakesh-garimella)

**Source:** [opentelemetry-collector-contrib](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/k8sleaderelector)

## Overview

## How It Works

The extension uses k8s.io/client-go/tools/leaderelection to perform leader election. The component that owns the lease becomes the leader and runs the function defined in onStartedLeading. If the leader loses the lease, it runs the function defined in onStoppedLeading, stops its operation, and waits to acquire the lease again.

## Configuration

```yaml theme={null}
receivers:
  my_awesome_receiver:
    k8s_leader_elector: k8s_leader_elector
extensions:
  k8s_leader_elector:
    auth_type: kubeConfig
    lease_name: foo
    lease_namespace: default

service:
  extensions: [k8s_leader_elector]
  pipelines:
    metrics:
      receivers: [my_awesome_receiver]
```

### Leader Election Configuration

| configuration        | description                                                                   | default value   |
| -------------------- | ----------------------------------------------------------------------------- | --------------- |
| **auth\_type**       | Authorization type to be used (serviceAccount, kubeConfig).                   | none (required) |
| **lease\_name**      | The name of the lease object.                                                 | none (required) |
| **lease\_namespace** | The namespace of the lease object.                                            | none (required) |
| **lease\_duration**  | The duration of the lease.                                                    | 15s             |
| **renew\_deadline**  | The deadline for renewing the lease. It must be less than the lease duration. | 10s             |
| **retry\_period**    | The period for retrying the leader election.                                  | 2s              |

### Delete the lease object

```shell theme={null}
kubectl delete leases.coordination.k8s.io -n <namespace> <lease_name>
```

### Suggested RBAC

```yaml theme={null}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: my-lease
  namespace: default
rules:
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
```

## Configuration

### Example Configuration

```yaml theme={null}
k8s_leader_elector/defaults:
  auth_type: kubeConfig
  lease_name: foo
  lease_namespace: default
k8s_leader_elector/with_lease_duration:
  auth_type: kubeConfig
  lease_name: bar
  lease_namespace: default
  lease_duration: 20s
```

***

*Last generated: 2026-07-06*
