Pending Workloads in Grafana

Monitoring Pending Workloads using the VisibilityOnDemand feature in Grafana.

This guide explains how to monitor pending workloads in Grafana using the VisibilityOnDemand feature.

The intended audience for this page are batch administrators for ClusterQueue visibility, and batch users for LocalQueue visibility.

Before you begin

Make sure the following conditions are met:

Setting Up Grafana for Pending Workloads

Step 1: Configure Cluster Permissions

To enable visibility, create a ClusterRole and ClusterRoleBinding for either ClusterQueue or LocalQueue:

  • For ClusterQueue visibility:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: grafana-cluster-queue-reader
rules:
  - apiGroups: ["visibility.kueue.x-k8s.io"]
    resources: ["clusterqueues/pendingworkloads"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["kueue.x-k8s.io"]
    resources: ["clusterqueues"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: grafana-cluster-queue-reader-binding
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: grafana-cluster-queue-reader
  apiGroup: rbac.authorization.k8s.io
  • For LocalQueue visibility:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: grafana-local-queue-reader
rules:
  - apiGroups: ["visibility.kueue.x-k8s.io"]
    resources: ["localqueues/pendingworkloads"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["kueue.x-k8s.io"]
    resources: ["localqueues"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["namespaces"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: grafana-local-queue-reader-binding
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: grafana-local-queue-reader
  apiGroup: rbac.authorization.k8s.io

Apply the appropriate configuration:

kubectl apply -f <filename>.yaml

Step 2: Generate a Service Account Token

Create a token for Grafana authentication:

TOKEN=$(kubectl create token default -n default)
echo $TOKEN

Save the token for use in Step 5.

Step 3: Set up port forwarding for Grafana

Access Grafana locally:

kubectl port-forward -n monitoring service/grafana 3000:3000

Grafana is now available at http://localhost:3000.

Step 4: Install the Infinity Plugin

  1. Open Grafana at http://localhost:3000.
  2. Log in (default credentials: admin/admin).
  3. Go to Connections > Add new connection.
  4. Search for Infinity and click Install.

Step 5: Configure the Infinity Data Source

  1. Go to Connections > Data sources and click + Add new data source.
  2. Select Infinity.
  3. Configure the data source:
    • Authentication: Set the Bearer Token to the token generated in Step 2.
    • Network: Enable Skip TLS Verify.
    • Security: Add https://kubernetes.default.svc to allowed hosts and set Query security to Allowed.
  4. Click Save & test to verify the configuration.

Step 6: Import the Pending Workloads Dashboard

  1. Download the appropriate dashboard JSON:
  2. In Grafana, go to Dashboards > New > Import.
  3. Select Upload dashboard JSON file and choose the downloaded file.
  4. Select the Infinity data source configured in Step 5.
  5. Click Import.

Step 7: Set Up ClusterQueue

To configure a basic ClusterQueue, apply the following:

apiVersion: kueue.x-k8s.io/v1beta2
kind: ResourceFlavor
metadata:
  name: "default-flavor"
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: ClusterQueue
metadata:
  name: "cluster-queue"
spec:
  namespaceSelector: {} # match all.
  resourceGroups:
  - coveredResources: ["cpu", "memory"]
    flavors:
    - name: "default-flavor"
      resources:
      - name: "cpu"
        nominalQuota: 9
      - name: "memory"
        nominalQuota: 36Gi
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: LocalQueue
metadata:
  namespace: "default"
  name: "user-queue"
spec:
  clusterQueue: "cluster-queue"

Apply the configuration:

kubectl apply -f https://kueue.sigs.k8s.io/examples/admin/single-clusterqueue-setup.yaml

Step 8: Create Sample Workloads

To populate the dashboard with data, create sample jobs:

apiVersion: batch/v1
kind: Job
metadata:
  generateName: sample-job-
  namespace: default
  labels:
    kueue.x-k8s.io/queue-name: user-queue
spec:
  parallelism: 3
  completions: 3
  template:
    spec:
      containers:
      - name: dummy-job
        image: registry.k8s.io/e2e-test-images/agnhost:2.53
        command: [ "/bin/sh" ]
        args: [ "-c", "sleep 60" ]
        resources:
          requests:
            cpu: "1"
            memory: "200Mi"
      restartPolicy: Never

Apply the job multiple times:

for i in {1..6}; do kubectl create -f https://kueue.sigs.k8s.io/examples/jobs/sample-job.yaml; done

Step 9: View the Dashboard

  1. In Grafana, navigate to Dashboards.
  2. Select the imported dashboard (e.g., “Pending Workloads for ClusterQueue visibility”).
  3. Verify that pending workloads are displayed.

ClusterQueue Visibility Dashboard

LocalQueue Visibility Dashboard

Use Grafana Cloud

The Prometheus metrics, such as kueue_pending_workloads, report the number of pending Workloads. They do not report the position of each Workload in a queue. That information comes from the visibility API, which Grafana can only query if it reaches the Kubernetes API server.

Grafana Cloud runs outside your cluster, so it cannot reach https://kubernetes.default.svc directly. Use private data source connect (PDC) to route the Infinity data source queries through an agent running inside the cluster. PDC opens an outbound connection from the agent, so you do not need to expose the Kubernetes API server to the internet.

Before you begin, make sure the prerequisites are met, except for Prometheus Operator. You also need an administrator account for your Grafana Cloud organization.

  1. Complete Step 1 and Step 2. The token created by kubectl create token expires, by default after one hour. The --duration flag only requests a lifetime, and the API server can issue a shorter one. To check when the token you received expires, run:

    echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | jq -R '@base64d | fromjson | .exp | todate'
    

    When the token expires, the Infinity queries fail and the dashboard stops showing queue positions. To renew it, run kubectl create token again and replace the Bearer Token in the Infinity data source. To avoid renewing, use a long-lived ServiceAccount token, which does not expire.

  2. Deploy a PDC agent in the cluster by following Configure private data source connect. The agent must run in the cluster so that it can resolve kubernetes.default.svc.

  3. In Grafana Cloud, install the Infinity data source plugin and add an Infinity data source with the following settings:

    • Authentication: Set the Bearer Token to the token generated in step 1.

    • Allowed hosts: Add https://kubernetes.default.svc.

    • TLS: Enable With CA cert, set Server name to kubernetes.default.svc, and provide the cluster CA certificate, which you can print with the following command:

      kubectl get configmap kube-root-ca.crt -n default -o jsonpath='{.data.ca\.crt}'
      

      Verifying the certificate prevents an impersonated API server from receiving the bearer token. Use Skip TLS Verify only temporarily to troubleshoot.

    • Private data source connect: Select the PDC connection created in step 2.

    • Health check: In the Health check section, enable the custom health check and set the URL to https://kubernetes.default.svc/version. The health check passes when the URL returns HTTP 200.

    Click Save & test to verify the configuration. Without a custom health check, Save & test does not send a request to the Kubernetes API server, so it does not confirm that Grafana Cloud reaches the API server through the PDC agent.

  4. Complete Step 6 in Grafana Cloud, selecting the data source from the previous step. Then, create sample Workloads as described in Step 7 and Step 8, and view the dashboard.

You can keep the existing Prometheus-based dashboards in Grafana Cloud. See Common Grafana queries for queries that use the Kueue metrics.

Troubleshooting

No data in dashboard

Ensure jobs are created and the Infinity data source is correctly configured.

Permission errors

Verify the ClusterRole and ClusterRoleBinding are applied correctly.

Grafana inaccessible

Check port forwarding and ensure the Grafana service is running in the monitoring namespace.