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

# Leader election

> Ensure that only one collector manager pod is active at a time to maintain high availability.

## Steps to ensure leader election

<Steps>
  <Step title="Check for the active leader pod">
    Run the following command to confirm that only one collector manager pod is active as the leader:

    ```shell theme={"system"}
    kubectl get pods -A -l collector-manager/leader=true
    ```

    **Example output:**

    ```
    NAME                                         READY   STATUS    RESTARTS   AGE
    plerion-collector-manager-ccbc55c5d-dr27w    1/1     Running   0          10m
    ```

    Only one pod should appear in the output. If multiple pods are listed, continue with the next steps.
  </Step>

  <Step title="Validate configuration">
    Ensure that leader election is enabled in the collector manager configmap:

    ```shell theme={"system"}
    kubectl get configmap plerion-collector-manager -n plerion-system \
      -o go-template='{{.data.LEADER_ELECTION}}'
    ```

    The value should be `true`.

    See [Validate Helm release](/guides/integrations/kubernetes/collector-manager/installation/installation-validation) for steps to confirm your configuration.
  </Step>

  <Step title="Check pod logs for leader activity">
    If multiple pods appear as leaders, verify that only one pod is active and the others are waiting to acquire the lease or shutting down.

    View logs for a specific pod:

    ```shell theme={"system"}
    kubectl logs -f plerion-collector-manager-ccbc55c5d-dr27w
    ```

    **Example logs for a pod waiting to acquire the lease:**

    ```
    {"level":"info","ts":"2023-11-21T03:33:01Z","logger":"setup","msg":"initializing controller"}
    {"level":"info","ts":"2023-11-21T03:33:01Z","logger":"setup","msg":"fetching tenant config"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":8080"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"starting manager"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"Starting server","kind":"health probe","addr":"[::]:8081"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"starting server","path":"/metrics","kind":"metrics","addr":":8080"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","msg":"attempting to acquire leader lease plerion-system/ecaf1259.collector.plerion.com...\\n"}
    ```

    **Example logs for a pod that has acquired the lease:**

    ```
    {"level":"info","ts":"2023-11-21T03:33:01Z","logger":"setup","msg":"initializing controller"}
    {"level":"info","ts":"2023-11-21T03:33:01Z","logger":"setup","msg":"fetching tenant config"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":8080"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"starting manager"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"Starting server","kind":"health probe","addr":"[::]:8081"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","logger":"setup","msg":"starting server","path":"/metrics","kind":"metrics","addr":":8080"}
    {"level":"info","ts":"2023-11-21T03:33:08Z","msg":"attempting to acquire leader lease plerion-system/ecaf1259.collector.plerion.com...\\n"}
    {"level":"info","ts":"2023-11-21T03:33:25Z","msg":"successfully acquired lease plerion-system/ecaf1259.collector.plerion.com\\n"}
    {"level":"info","ts":"2023-11-21T03:33:25Z","logger":"setup","msg":"Starting EventSource","controller":"resourcecollector","source":"<redacted>"}
    {"level":"info","ts":"2023-11-21T03:33:25Z","logger":"setup","msg":"Starting Controller","controller":"resourcecollector"}
    {"level":"info","ts":"2023-11-21T03:33:25Z","logger":"setup","msg":"Starting workers","controller":"resourcecollector","worker count":1}
    ```
  </Step>
</Steps>

<Warning>
  If leader election cannot be ensured in the current release, reinstall the collector manager.

  Follow the [uninstall](/guides/integrations/kubernetes/collector-manager/uninstall) and [install](/guides/integrations/kubernetes/collector-manager/installation/installation) guides to reset the deployment.
</Warning>
