K3s Metrics

Published
Length
3 min read

Luis Felipe Dias

All posts

You collect k3s metrics by reading data from the built-in metrics server. You can also scrape node and control plane endpoints with a monitoring tool. Platform teams often start by giving engineers broad cluster roles to check these charts. When roles are too broad, a user checking CPU load can also read secrets. This wide access turns a simple health check into a real security risk. How k3s metrics work inside your cluster K3s ships with a lightweight metrics server turned on from the start.

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You collect k3s metrics by reading data from the built-in metrics server. You can also scrape node and control plane endpoints with a monitoring tool. Platform teams often start by giving engineers broad cluster roles to check these charts. When roles are too broad, a user checking CPU load can also read secrets. This wide access turns a simple health check into a real security risk.

How k3s metrics work inside your cluster

K3s ships with a lightweight metrics server turned on from the start. This component talks to each node kubelet to gather CPU and memory stats. It stores short-term numbers in memory so teams can check pod health right away. It does not save long-term history to a disk on its own.

To keep history, teams deploy an external collector inside or outside the cluster. This collector pulls numbers from the API server, the kubelet, and the container runtime. Each endpoint needs a valid cluster role to read those health endpoints. Teams create a service account and bind it to a read role. Human users also need a role binding to query the metrics API. The cluster checks the user token and matches it against role rules. If the role allows read actions on metrics resources, the API returns the stats.

Why native roles are not enough for cluster safety

Native cluster roles do a good job of sorting out who can log in. They let you group users and grant read or write rules on cluster objects. For basic k3s metrics collection, a simple view role lets someone see node load. The problem starts when an engineer needs to fix a slow pod.

A view role is rarely enough to fix a broken app in production. Teams end up granting edit or admin roles so on-call staff can run checks. Once a user has that role, the cluster trusts every command they send. Native roles decide who logs in, not what individual commands do in flight.

An engineer with a broad role can exec into a pod or dump logs. Those logs and app states often hold emails, phone numbers, or card numbers. Static kubeconfig files also sit on laptops for months without expiring. If a key leaks, an attacker gets full control over the cluster API. You also lack a clear audit trail of the exact commands run during incidents. Native API logs show resource calls, not the terminal output seen by the user.

Security Metrics & KPIs: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Securing cluster checks at the command level

To close this gap, teams must move away from static cluster keys. You should check every command and API request right when someone sends it. Instead of granting full admin roles all day, require approval for sensitive actions. A team lead can review the exact pod command before it runs.

You can also protect sensitive data that flows back from pod logs or checks. Real-time data masking rewrites matched fields in results, such as national IDs or emails. This lets engineers check app health and read logs while keeping private fields safe. Tying every cluster action to an identity provider gives you a clear audit log. You see who ran what command, when they ran it, and who approved it.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. Data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Does K3s include a metrics server out of the box?

Yes, K3s runs a built-in metrics server by default when you start the cluster. It gathers basic CPU and memory numbers from every node and pod right away.

How do you store k3s metrics for long-term review?

The built-in server only holds current state in memory for quick checks. To keep history, you must deploy a time-series tool that scrapes the cluster endpoints.

Why are static kubeconfig files risky for viewing cluster health?

Static files often stay valid for months and sit unprotected on user laptops. If someone steals that file, they gain every permission tied to that cluster role.

The query runs. The emails stay hidden.