Pending Workloads 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:
- A Kubernetes cluster is running.
- Kueue v0.15.0 or later is installed.
- Prometheus Operator is installed. See Setup Prometheus for instructions.
- The VisibilityOnDemand feature is enabled.
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
ClusterQueuevisibility:
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
LocalQueuevisibility:
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
- Open Grafana at http://localhost:3000.
- Log in (default credentials: admin/admin).
- Go to
Connections>Add new connection. - Search for
Infinityand clickInstall.
Step 5: Configure the Infinity Data Source
- Go to
Connections>Data sourcesand click+ Add new data source. - Select
Infinity. - Configure the data source:
- Authentication: Set the
Bearer Tokento the token generated in Step 2. - Network: Enable
Skip TLS Verify. - Security: Add
https://kubernetes.default.svcto allowed hosts and setQuery securitytoAllowed.
- Authentication: Set the
- Click
Save & testto verify the configuration.
Step 6: Import the Pending Workloads Dashboard
- Download the appropriate dashboard JSON:
- In Grafana, go to
Dashboards>New>Import. - Select
Upload dashboard JSONfile and choose the downloaded file. - Select the Infinity data source configured in Step 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
- In Grafana, navigate to
Dashboards. - Select the imported dashboard (e.g., “Pending Workloads for ClusterQueue visibility”).
- Verify that pending workloads are displayed.


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.
Complete Step 1 and Step 2. The token created by
kubectl create tokenexpires, by default after one hour. The--durationflag 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 tokenagain and replace theBearer Tokenin the Infinity data source. To avoid renewing, use a long-lived ServiceAccount token, which does not expire.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.NoteBy default, Grafana Cloud can connect to any host reachable from the PDC agent. Restrict the agent to the Kubernetes API server with the
-ssh-flag='-o PermitRemoteOpen=kubernetes.default.svc:443'flag. For details, see Restrict accessible endpoints.In Grafana Cloud, install the Infinity data source plugin and add an Infinity data source with the following settings:
Authentication: Set the
Bearer Tokento the token generated in step 1.Allowed hosts: Add
https://kubernetes.default.svc.TLS: Enable
With CA cert, setServer nametokubernetes.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 Verifyonly temporarily to troubleshoot.Private data source connect: Select the PDC connection created in step 2.
Health check: In the
Health checksection, enable the custom health check and set the URL tohttps://kubernetes.default.svc/version. The health check passes when the URL returns HTTP 200.
Click
Save & testto verify the configuration. Without a custom health check,Save & testdoes 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.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.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.