# Configure the agent

> Chart values for the LevelFour agent, and how to read Prometheus history, publish cost metrics, measure network by destination, turn on the JVM reader, send through a proxy, pull from a private registry and verify the release signatures.

Source: https://docs.levelfour.ai/kubernetes/configuration


Helm installs and GitOps installs take the same chart values. With GitOps, add them to [your values](/kubernetes/gitops#point-your-gitops-tool-at-the-chart). With Helm, apply a values file over the install you have:

```bash
helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent \
  --version 0.8.6 \
  --namespace levelfour --reset-then-reuse-values -f values.yaml
```

Set `--version` to the chart version you run. Without it, Helm pulls the newest chart and upgrades the agent as well.

## Chart values

The chart validates its values and refuses to install when `clusterName` breaks the naming rule, when neither `token` nor `existingSecret.name` is set, when both are, when `automation.enabled` is `true` with no `automation.allowedNamespaces`, when an `automation.hardLimits` value is not positive, when an `automation` or `jvmReader` key is one it does not know, or when `jvmReader.namespace` is the release namespace.

| Value                                | Default                                                                      | What it sets                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------ | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clusterName`                        | none                                                                         | The cluster's name in LevelFour. Required. Lowercase letters, digits and hyphens, at most 63 characters, starting and ending with a letter or digit. Unique across your organization                                                                                                                                                                                                                                                                                                                     |
| `token`                              | none                                                                         | A cluster token (`l4k_...`) or an install key (`l4ki_...`). Set `token` or `existingSecret.name`, not both                                                                                                                                                                                                                                                                                                                                                                                               |
| `existingSecret.name`                | none                                                                         | A Secret in the release namespace that holds the token or install key                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `existingSecret.key`                 | `token`                                                                      | The key inside that Secret                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `apiUrl`                             | `https://api.levelfour.ai`                                                   | Where the agent sends data. Keep the default                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `prometheus.url`                     | none                                                                         | An in-cluster Prometheus to read usage and history from. See [Read history from Prometheus](#read-history-from-prometheus)                                                                                                                                                                                                                                                                                                                                                                               |
| `kubelet.insecureSkipTLSVerify`      | `false`                                                                      | Skips kubelet certificate checks, for local kind clusters only. On a real cluster it sends the agent's service account token to kubelets the agent cannot verify                                                                                                                                                                                                                                                                                                                                         |
| `image.repository`                   | `public.ecr.aws/levelfour/k8s-agent`                                         | The agent image. Point it at your [mirror](#private-registry-mirror)                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `image.tag`                          | The chart's version                                                          | Leave it unset so the image moves with the chart                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `image.digest`                       | none                                                                         | Pulls the image by digest (`sha256:...`) instead of by tag                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `image.pullPolicy`                   | `IfNotPresent`                                                               | `IfNotPresent`, `Always` or `Never`                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `imagePullSecrets`                   | `[]`                                                                         | Pull Secrets for a private registry                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `nameOverride`                       | none                                                                         | Replaces the chart name in object names and in the `app.kubernetes.io/name` label                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `fullnameOverride`                   | none                                                                         | Replaces the whole object name. A release named `levelfour-agent` names its objects `levelfour-agent`                                                                                                                                                                                                                                                                                                                                                                                                    |
| `serviceAccount.create`              | `true`                                                                       | Whether the chart creates the agent's service account                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `serviceAccount.name`                | The object name                                                              | The service account the agent runs as. With `create: false`, name one that exists                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `serviceAccount.annotations`         | `{}`                                                                         | Annotations on the service account the chart creates                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `commonLabels`                       | `{}`                                                                         | Labels added to every object the chart creates                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `podAnnotations`                     | `{}`                                                                         | Annotations on the agent pod                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `podLabels`                          | `{}`                                                                         | Labels on the agent pod, added to the chart's own                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `priorityClassName`                  | none                                                                         | The PriorityClass of the agent pod. Wins over `priorityClass.create`                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `priorityClass.create`               | `false`                                                                      | Creates a PriorityClass and gives it to the agent pod. On Spot or heavily consolidated nodes, turn it on: after an interruption the agent's pod is otherwise scheduled behind every other evicted pod and waits minutes for a new node, and those minutes are missing from the data. With the class it starts first, and with `PreemptLowerPriority` may evict one lower-priority pod to start on a running node. The class is cluster-scoped, so the install needs permission to create PriorityClasses |
| `priorityClass.value`                | `1000000`                                                                    | The class's priority, below the system classes                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `priorityClass.preemptionPolicy`     | `PreemptLowerPriority`                                                       | `Never` only puts the agent's pod first in the scheduling queue, without evicting anything                                                                                                                                                                                                                                                                                                                                                                                                               |
| `podSecurityContext`                 | Non-root user and group `65532`, `RuntimeDefault` seccomp                    | The pod security context                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `containerSecurityContext`           | No privilege escalation, read-only root filesystem, every capability dropped | The container security context                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `resources`                          | See [Footprint](/kubernetes/agent-permissions-and-data#footprint)            | CPU and memory requests and limits                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `metrics.port`                       | `9090`                                                                       | The port that serves `/metrics` and `/healthz`                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `metrics.costs.enabled`              | `false`                                                                      | Also serves this cluster's cost on `/metrics`. See [Cost metrics for your Prometheus](#cost-metrics-for-your-prometheus)                                                                                                                                                                                                                                                                                                                                                                                 |
| `serviceMonitor.enabled`             | `false`                                                                      | Creates a Prometheus Operator ServiceMonitor for `/metrics`. Needs the `monitoring.coreos.com` CRDs                                                                                                                                                                                                                                                                                                                                                                                                      |
| `serviceMonitor.labels`              | `{}`                                                                         | Labels your Prometheus selects ServiceMonitors by                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `grafanaDashboard.enabled`           | `false`                                                                      | Creates a ConfigMap with a LevelFour cost dashboard for Grafana's dashboard sidecar. Needs `metrics.costs.enabled`                                                                                                                                                                                                                                                                                                                                                                                       |
| `grafanaDashboard.labels`            | `grafana_dashboard: "1"`                                                     | Labels the sidecar loads dashboards by                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `netflow.enabled`                    | `false`                                                                      | Runs the netflow DaemonSet. See [Network by destination](#network-by-destination)                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `netflow.existingSecret.name`        | none                                                                         | A Secret in the release namespace that holds the token the agent and the netflow pods share, instead of the one the chart generates. Set it for GitOps installs. See [Network by destination](#network-by-destination)                                                                                                                                                                                                                                                                                   |
| `netflow.existingSecret.key`         | `token`                                                                      | The key inside that Secret                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `netflow.port`                       | `9188`                                                                       | The port each netflow pod answers the agent on, at its node's own address. The pods use the node's network, so pick a port free on every node                                                                                                                                                                                                                                                                                                                                                            |
| `netflow.resources`                  | Requests 50m CPU and 32 MiB, limits 200m CPU and 256 MiB                     | CPU and memory of each netflow pod. See the memory sizing under [Network by destination](#network-by-destination)                                                                                                                                                                                                                                                                                                                                                                                        |
| `netflow.tolerations`                | Tolerates every taint                                                        | Runs a netflow pod on every node, tainted ones included, so no node's traffic goes uncounted                                                                                                                                                                                                                                                                                                                                                                                                             |
| `netflow.priorityClassName`          | none                                                                         | The PriorityClass of the netflow pods                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `jvmReader.enabled`                  | `false`                                                                      | Runs the JVM reader DaemonSet. See [Turn on the JVM reader](#turn-on-the-jvm-reader)                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `jvmReader.namespace`                | `levelfour-jvm`                                                              | The namespace of the reader's pods. It must differ from the release namespace, because it allows privileged pods                                                                                                                                                                                                                                                                                                                                                                                         |
| `jvmReader.createNamespace`          | `true`                                                                       | Creates `jvmReader.namespace` with the Pod Security labels the reader needs. Set `false` to bring your own, labelled `pod-security.kubernetes.io/enforce: privileged`                                                                                                                                                                                                                                                                                                                                    |
| `jvmReader.existingSecret.name`      | none                                                                         | A Secret that holds the token the agent and the reader pods share, instead of the one the chart generates. It must exist in the release namespace and in `jvmReader.namespace`, with the same token. Set it for GitOps installs                                                                                                                                                                                                                                                                          |
| `jvmReader.existingSecret.key`       | `token`                                                                      | The key inside that Secret                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `jvmReader.requireLandlock`          | `true`                                                                       | Keeps the reader's server from serving on a node whose kernel cannot confine it with Landlock. Set `false` to let it serve there unconfined                                                                                                                                                                                                                                                                                                                                                              |
| `jvmReader.port`                     | `9189`                                                                       | The port each reader pod answers the agent on, at the pod's own address                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `jvmReader.interval`                 | `30s`                                                                        | How often the reader samples the JVMs on its node                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `jvmReader.namespaces`               | `[]`                                                                         | The only namespaces whose JVMs the reader reads. Empty reads every namespace but `kube-system`, the release namespace and the reader's own, which it never reads                                                                                                                                                                                                                                                                                                                                         |
| `jvmReader.nodeSelector`             | `{}`                                                                         | Narrows the nodes the reader runs on. It never runs on Windows nodes, EKS Fargate or virtual kubelets                                                                                                                                                                                                                                                                                                                                                                                                    |
| `jvmReader.tolerations`              | `[]`                                                                         | Taints the reader tolerates. Empty runs it on untainted nodes only                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `jvmReader.priorityClassName`        | none                                                                         | The PriorityClass of the reader pods                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `jvmReader.seLinuxOptions`           | `level: s0:c0.c1023`                                                         | The SELinux options of the probe container. See [Nodes it runs on](/kubernetes/agent-permissions-and-data#nodes-it-runs-on)                                                                                                                                                                                                                                                                                                                                                                              |
| `jvmReader.probe.resources`          | Requests 10m CPU and 48 MiB, limits 100m CPU and 128 MiB                     | CPU and memory of the probe container on each node                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `jvmReader.server.resources`         | Requests 5m CPU and 32 MiB, limits 100m CPU and 128 MiB                      | CPU and memory of the server container, which keeps three hours of samples                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `kro.instanceGroups`                 | `[]`                                                                         | API groups of kro instances outside `kro.run`. See [KNative and kro](/kubernetes/knative-and-kro#kro)                                                                                                                                                                                                                                                                                                                                                                                                    |
| `extraEnv`                           | `[]`                                                                         | Extra environment variables for the agent, such as a [proxy](#behind-a-proxy)                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `nodeSelector`                       | `kubernetes.io/os: linux`                                                    | Node selector for the agent pod                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `tolerations`                        | `[]`                                                                         | Tolerations for the agent pod                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `affinity`                           | `{}`                                                                         | Affinity rules for the agent pod                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `automation.enabled`                 | `false`                                                                      | Installs the [automation component](/kubernetes/automation) and its [configuration objects](/kubernetes/automation#configure-it-in-the-cluster), with its own service account and permissions. It changes nothing until an object or an admin in the dashboard turns automation on                                                                                                                                                                                                                       |
| `automation.allowedNamespaces`       | `[]`                                                                         | The namespaces the component may change. Required when `automation.enabled` is `true`. `["*"]` grants it the whole cluster and makes it watch every pod, so a list is lighter on a big cluster                                                                                                                                                                                                                                                                                                           |
| `automation.hardLimits.maximumCores` | `8`                                                                          | The most CPU, in cores, the component or its webhook sets on one container, request or limit, whatever an object or the dashboard asks for. A container never goes past double its workload's own spec either way                                                                                                                                                                                                                                                                                        |
| `automation.hardLimits.maximumGiB`   | `16`                                                                         | The same ceiling for memory, in GiB                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `automation.revert.allowPodEviction` | `false`                                                                      | Lets a revert evict a pod whose memory limit cannot go back down in place, on Kubernetes 1.33 and 1.34. Only this value allows an eviction                                                                                                                                                                                                                                                                                                                                                               |
| `automation.resources`               | requests `20m`, `128Mi`; limits `200m`, `256Mi`                              | The component's own resources. Its pod cache grows with the pods in the allowed namespaces, so raise the memory limit for `["*"]` on a big cluster                                                                                                                                                                                                                                                                                                                                                       |
| `automation.priorityClassName`       | none                                                                         | The PriorityClass of the component's pod and of the webhook's pods                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `automation.webhook.enabled`         | `false`                                                                      | Installs the admission webhook that gives each new pod of a rightsized workload its values. Needs `automation.enabled`, and the control plane must reach its pods on port 9443                                                                                                                                                                                                                                                                                                                           |
| `automation.webhook.resources`       | requests `20m`, `64Mi`; limits `200m`, `128Mi`                               | Each webhook pod's resources. Its cache holds the rightsized values of the allowed namespaces                                                                                                                                                                                                                                                                                                                                                                                                            |

## Read history from Prometheus

The agent measures usage from the kubelet on each node, so it needs no Prometheus. If the cluster already runs one, such as kube-prometheus-stack, point the agent at it. At its first start the agent reads up to 14 days of history from Prometheus, so the first recommendations can come sooner than 7 days after install.

```yaml title="values.yaml"
prometheus:
  url: http://prometheus-operated.monitoring.svc:9090
```

With Helm, set it on the command line:

```bash
helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent \
  --version 0.8.6 \
  --namespace levelfour --reset-then-reuse-values \
  --set prometheus.url=http://prometheus-operated.monitoring.svc:9090
```

The agent queries Prometheus from inside the cluster. LevelFour never connects to it, and nothing is exposed outside the cluster.

With `prometheus.url` set, the agent reads all usage from Prometheus and no longer calls the kubelets, so the nodes need no inbound rule on port 10250 for it. That Prometheus has to scrape each kubelet's cAdvisor endpoint (`/metrics/cadvisor`) and the kubelet's own metrics, as kube-prometheus-stack does by default. The agent reads container CPU, memory, file system, throttling and network from cAdvisor, and volume use from `kubelet_volume_stats_used_bytes`. [Usage shows for one node only](/kubernetes/troubleshooting#usage-shows-for-one-node-only) covers the port 10250 rule for an agent that reads the kubelets.

### GPU usage from DCGM

When the same Prometheus scrapes NVIDIA's [DCGM exporter](https://github.com/NVIDIA/dcgm-exporter), the agent also reads each container's GPU utilization and GPU memory, and the workload drawer shows them beside the GPUs it requested. The exporter's Helm chart creates the ServiceMonitor that kube-prometheus-stack picks up. Without the exporter, GPU usage reads as not measured, and nothing else changes.

## Cost metrics for your Prometheus

With `metrics.costs.enabled`, the agent's ingest token also reads this cluster's cost from LevelFour once an hour, and the agent republishes it in the cluster on the same `/metrics` port, to anyone who can reach that port. Chart your LevelFour cost in your own Grafana, next to the rest of your metrics.

```yaml title="values.yaml"
metrics:
  costs:
    enabled: true
serviceMonitor:
  enabled: true
  labels:
    release: kube-prometheus-stack
grafanaDashboard:
  enabled: true
```

Each series carries a `window` label: `last_day`, the last day the bill priced, or `month_to_date`. Each window carries the 500 costliest workloads, and sums the rest into one series whose namespace, kind and workload are `__other__`.

| Metric                                                         | What it is                                                                  |
| -------------------------------------------------------------- | --------------------------------------------------------------------------- |
| `levelfour_namespace_cost_usd{namespace,window}`               | A namespace's cost                                                          |
| `levelfour_workload_cost_usd{namespace,kind,workload,window}`  | A workload's cost                                                           |
| `levelfour_workload_waste_usd{namespace,kind,workload,window}` | The cost of what a workload requested and did not use                       |
| `levelfour_cluster_idle_cost_usd{window}`                      | The cost of node capacity no workload requested                             |
| `levelfour_cost_day_timestamp_seconds`                         | The start of the last priced day, as a Unix time. `0` until a day is priced |

`serviceMonitor.labels` has to match what your Prometheus selects. kube-prometheus-stack selects ServiceMonitors labelled `release: <its release name>`, and its Grafana dashboard sidecar loads ConfigMaps labelled `grafana_dashboard: "1"`, the chart's default ([kube-prometheus-stack values](https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml)).

When a read fails, or LevelFour answers in a currency other than US dollars, the agent keeps serving the last values it had, and `levelfour_cost_day_timestamp_seconds` shows how old they are. A scrape always sees one whole refresh.

## Network by destination

The agent counts the bytes each workload sends, but not where they go. With `netflow.enabled`, the chart adds a DaemonSet, one pod per node, that measures where: a workload in the same zone or another zone, a node, a private address outside the cluster, or the internet. LevelFour then splits each node's data transfer bill by it, so cross-zone and internet egress cost lands on the workloads that cause it. AWS bills a byte that crosses zones on both nodes, the one it leaves and the one it reaches, so the cost of a zone pair counts both ends.

```yaml title="values.yaml"
netflow:
  enabled: true
```

Each netflow pod reads its node's connection tracking table (conntrack) every 10 seconds, or every ten times as long as its last read took when that is longer, and watches only the pods on its own node. A receiver with a public IPv4 address counts as `internet`, and the netflow pod drops the address at once. Every other receiver, a private IPv4 address or any IPv6 address that is not loopback or link-local, keeps its address only as far as the agent, inside the cluster. The agent names it from the pods and nodes it already watches: a pod becomes its workload and zone, a node becomes `node`, and an address it does not know becomes `private` inside a private range and `internet` outside one. No address reaches LevelFour. The agent reads each node one minute late, and tries a node twice more after a connection failure, a server error or a refused token before that window goes without it. Reading conntrack takes privileges the agent never has: [The netflow component](/kubernetes/agent-permissions-and-data#the-netflow-component) lists each one and why.

The netflow pods answer only the agent, with a token they share. The chart generates it in a Secret of its own. Argo CD and Flux render the chart with `helm template`, which generates a new token on every sync, so the netflow pods would refuse the agent until both sides reload. For a GitOps install, create the token once in the release namespace and point the chart at it:

```bash
kubectl -n levelfour create secret generic levelfour-netflow-token --from-literal=token="$(openssl rand -hex 32)"
```

```yaml title="values.yaml"
netflow:
  enabled: true
  existingSecret:
    name: levelfour-netflow-token
```

Each netflow pod holds about 1 KiB per connection its node tracks, on top of about 30 MiB, and its `GOMEMLIMIT` follows the container's memory limit. The default 256 MiB fits about 200,000 tracked connections. Check a node with `cat /proc/sys/net/netfilter/nf_conntrack_count`, and raise `netflow.resources.limits.memory` for busier nodes.

> **Warning**
>
> Netflow sees only traffic that passes through the node's netfilter. Cilium with eBPF host routing, which Cilium turns on together with eBPF kube-proxy replacement when the kernel supports it, and Cilium's `installNoConntrackIptablesRules` both bypass it, so netflow reads nothing there. Cilium with `bpf.hostLegacyRouting=true` works. [Cilium's tuning guide](https://docs.cilium.io/en/stable/operations/performance/tuning/) describes both settings.

Netflow also misses:

* Pods on the host network. Their traffic is the node's own.
* A connection whose conntrack entry is gone before the next read. The kernel keeps a closed TCP connection's entry for 2 minutes by default, so short requests count in full. What can go missing is a connection reset by either side, whose entry lasts 10 seconds, and an entry the kernel drops early because the table is full.
* Traffic to a pod that ended before the agent read the window. The agent no longer knows that pod, so the traffic counts as `private` or `internet` by its address.
* Windows nodes. The DaemonSet runs on Linux nodes only.

The **Network** view on the cluster page shows the result under **By destination**: bytes and cost between each pair of zones, internet egress per workload, and how the measured gigabytes compare with the gigabytes the bill charged.

## Turn on the JVM reader

The agent reads a JVM's heap from the pod spec only where `-Xmx` sets it plainly. With `jvmReader.enabled`, the chart adds the JVM reader, a DaemonSet that reads the heap, garbage collection and options of each running HotSpot JVM on its node. [The measured heap](/kubernetes/recommendations#the-measured-heap) explains what LevelFour does with them. It runs in a namespace of its own, `levelfour-jvm`, which allows privileged pods, and its `probe` container runs as root in the node's process namespace with `SYS_PTRACE`. Read [The JVM reader](/kubernetes/agent-permissions-and-data#the-jvm-reader) for each privilege, what it reads and what it sends before you turn it on.

### Upgrade with the reader off

Upgrade to 0.8.6 first. The reader stays off, its default:

```bash
helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6 \
  --namespace levelfour --reset-then-reuse-values
```

`--reset-then-reuse-values` keeps the token and the values you installed with, and applies the new chart's defaults, the reader's among them. It needs Helm 3.14 or later, as [Upgrade](/kubernetes/upgrade) explains.

### Turn the reader on

Pick the tab for the admission checks your cluster runs.

**Pod Security only**

On a cluster whose only admission check is Pod Security, this is one command. The chart creates `levelfour-jvm` labelled `privileged`:

```bash
helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6 \
  --namespace levelfour --reset-then-reuse-values --set jvmReader.enabled=true
```

**Kyverno or Gatekeeper**

Where Kyverno or Gatekeeper may refuse the reader, find out before anything runs. `helm upgrade --dry-run=server` cannot tell you: Helm renders the chart with the cluster's data and stops before it sends an object, so no admission webhook sees one. A `kubectl` server-side dry run goes through the admission chain, but only into a namespace that exists, so bring your own namespace:

1. Create the reader's namespace, labelled for privileged pods. If your cluster runs Kyverno's `deny-privileged-profile`, only a user bound to the `cluster-admin` ClusterRole may set that label.

   ```bash
   kubectl create namespace levelfour-jvm
   kubectl label namespace levelfour-jvm pod-security.kubernetes.io/enforce=privileged
   ```

2. Apply the [Kyverno exception](#kyverno-exceptions) or the [Gatekeeper exclusion](#gatekeeper-exclusion), if your cluster runs either.

3. Dry-run the DaemonSet with your release's values. `helm template` renders it and sends nothing. `kubectl` sends it to the API server as a dry run, which goes through every admission webhook and stores nothing.

   ```bash
   helm get values levelfour-agent --namespace levelfour --output yaml \
     | helm template levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6 \
         --namespace levelfour --values - \
         --set jvmReader.enabled=true --set jvmReader.createNamespace=false \
         --show-only templates/jvmreader-daemonset.yaml \
     | kubectl apply --dry-run=server --filename -
   ```

   `daemonset.apps/levelfour-agent-jvm-reader created (server dry run)` means admission let it through. A refusal names the webhook and each policy, with the rule for a `ClusterPolicy`. Copy those names into the exception, then run the dry run again.

4. Turn the reader on in your namespace:

   ```bash
   helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6 \
     --namespace levelfour --reset-then-reuse-values \
     --set jvmReader.enabled=true --set jvmReader.createNamespace=false
   ```

### Check every node

```bash
kubectl --namespace levelfour-jvm get daemonset levelfour-agent-jvm-reader
kubectl --namespace levelfour-jvm get events --field-selector reason=FailedCreate
```

**READY** matches **DESIRED** once every node the reader may run on has a ready pod. A `FailedCreate` event names a pod an admission check refused. Pod Security, and Gatekeeper without workload expansion, check the pods and not the DaemonSet, so their refusals show up here, after a dry run that passed.

From agent 0.8.1, the agent runs the same check every hour. A refused reader pod, a node with a taint the reader does not tolerate, and processes or JVMs the kernel hid from the reader turn its JVM reader health from OK to an error that names them.

### Pod Security

The probe fails the `baseline` and `restricted` levels. The chart labels the namespace it creates `privileged` for `enforce`, `warn` and `audit`. With `jvmReader.createNamespace=false` the namespace is yours, and it needs `pod-security.kubernetes.io/enforce: privileged`.

### Kyverno exceptions

Kyverno 1.19 ships with exceptions off. Its admission controller needs `--enablePolicyException=true` and `--exceptionNamespace=<namespace>` (`features.policyExceptions.enabled` and `features.policyExceptions.namespace` in its Helm chart), and it reads exceptions only from that namespace, or from all of them with `*`. Ask your Kyverno admins which namespace it is. The exception's kind follows the policy that refused:

* A `ClusterPolicy` or `Policy` takes a `kyverno.io/v2` PolicyException, which Kyverno 1.19 deprecates. Its `policyName` takes no wildcard, and `ruleNames` does. Kyverno checks the DaemonSet with the rule it generated from each Pod rule, named `autogen-<rule>`, and the pods with the rule itself, so list both.
* A `ValidatingPolicy` takes a `policies.kyverno.io/v1` PolicyException. It names policies in `policyRefs`, by exact name, and picks resources with CEL `matchConditions`. These policies have no rules to name.

These stock policies from kyverno/policies refuse the reader. The first five come in its `pod-security`, `pod-security-cel` and `pod-security-vpol` sets under the same names, and the `kyverno-policies` Helm chart installs them as `ValidatingPolicy`, or as `ClusterPolicy` with `policyType=ClusterPolicy`:

| Policy                                             | Rule                         | What it refuses                                                                     |
| -------------------------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------- |
| `disallow-host-namespaces` (baseline)              | `host-namespaces`            | `hostPID`                                                                           |
| `disallow-capabilities` (baseline)                 | `adding-capabilities`        | `SYS_PTRACE`, which is not on its list                                              |
| `disallow-capabilities-strict` (restricted)        | `adding-capabilities-strict` | Any added capability but `NET_BIND_SERVICE`                                         |
| `require-run-as-nonroot` (restricted)              | `run-as-non-root`            | `runAsNonRoot: false`                                                               |
| `require-run-as-non-root-user` (restricted)        | `run-as-non-root-user`       | `runAsUser: 0`                                                                      |
| `require-pod-probes` (best practices)              | `validate-probes`            | A container with no liveness, readiness or startup probe, as the probe container is |
| `deny-privileged-profile` (Pod Security Admission) | `check-privileged`           | The `privileged` namespace label, from anyone not bound to `cluster-admin`          |

They ship in `Audit` mode, which reports and refuses nothing. A copy that refuses was set to `Enforce` (`Deny` for a `ValidatingPolicy`), and your copies may carry other names, so take the policy and rule names from the dry run's refusal. The stock `disallow-selinux` checks the SELinux type, user and role, so the probe's level passes it. LevelFour checked these exceptions on Kyverno 1.19.2.

For a `ClusterPolicy`, in your exception namespace:

```yaml title="levelfour-jvm-reader-exception.yaml"
apiVersion: kyverno.io/v2
kind: PolicyException
metadata:
  name: levelfour-jvm-reader
  namespace: <exceptionNamespace>
spec:
  exceptions:
    - policyName: disallow-host-namespaces
      ruleNames: [host-namespaces, autogen-host-namespaces]
    - policyName: disallow-capabilities
      ruleNames: [adding-capabilities, autogen-adding-capabilities]
    - policyName: disallow-capabilities-strict
      ruleNames: [adding-capabilities-strict, autogen-adding-capabilities-strict]
    - policyName: require-run-as-nonroot
      ruleNames: [run-as-non-root, autogen-run-as-non-root]
    - policyName: require-run-as-non-root-user
      ruleNames: [run-as-non-root-user, autogen-run-as-non-root-user]
    - policyName: require-pod-probes
      ruleNames: [validate-probes, autogen-validate-probes]
  match:
    any:
      - resources:
          kinds: [DaemonSet, Pod]
          namespaces: [levelfour-jvm]
          names: [levelfour-agent-jvm-reader*]
```

For a `ValidatingPolicy`:

```yaml title="levelfour-jvm-reader-exception.yaml"
apiVersion: policies.kyverno.io/v1
kind: PolicyException
metadata:
  name: levelfour-jvm-reader
  namespace: <exceptionNamespace>
spec:
  policyRefs:
    - {kind: ValidatingPolicy, name: disallow-host-namespaces}
    - {kind: ValidatingPolicy, name: disallow-capabilities}
    - {kind: ValidatingPolicy, name: disallow-capabilities-strict}
    - {kind: ValidatingPolicy, name: require-run-as-nonroot}
    - {kind: ValidatingPolicy, name: require-run-as-non-root-user}
    - {kind: ValidatingPolicy, name: require-pod-probes}
  matchConditions:
    - name: levelfour-jvm-reader
      expression: >-
        object.metadata.namespace == 'levelfour-jvm' &&
        object.metadata.name.startsWith('levelfour-agent-jvm-reader')
```

Each matches the DaemonSet and its pods in `levelfour-jvm` for a release named `levelfour-agent`. Keep the entries your dry run names and drop the rest.

### Gatekeeper exclusion

Gatekeeper's library constraints match Pods, so Gatekeeper refuses the reader's pods and lets the DaemonSet through, unless your Gatekeeper validates workloads through expansion. To leave the reader's namespace out of every constraint, add it to `excludedNamespaces` under `spec.match` of the `Config` resource named `config` in `gatekeeper-system`, with `processes: ["webhook"]`, or `["*"]` to leave it out of audit too. For one constraint, use that constraint's `spec.match.excludedNamespaces`. With the `admission.gatekeeper.sh/ignore` label, the API server stops calling Gatekeeper's webhook for anything in the namespace, and Gatekeeper allows that label only on a namespace listed in its `--exempt-namespace` flag.

### GitOps installs

The chart generates the reader's token in a Secret in both namespaces. Argo CD and Flux render the chart with `helm template`, which cannot read the Secret the chart made before, so every sync would generate a new token and the reader would refuse the agent until both sides reload. For a GitOps install, create the reader's namespace and its token once, with the same token in the release namespace and in `levelfour-jvm`:

```bash
kubectl create namespace levelfour-jvm
kubectl label namespace levelfour-jvm pod-security.kubernetes.io/enforce=privileged
TOKEN="$(openssl rand -hex 32)"
kubectl -n levelfour create secret generic levelfour-jvm-reader-token --from-literal=token="$TOKEN"
kubectl -n levelfour-jvm create secret generic levelfour-jvm-reader-token --from-literal=token="$TOKEN"
```

Then pin chart version 0.8.6, as [Upgrade](/kubernetes/upgrade) shows for each tool, and add the reader to your values:

```yaml title="values.yaml"
jvmReader:
  enabled: true
  createNamespace: false
  existingSecret:
    name: levelfour-jvm-reader-token
```

With Kyverno or Gatekeeper, add the exception before you commit the values, and run the dry run from the **Kyverno or Gatekeeper** tab first.

### Turn it off

```bash
helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6 \
  --namespace levelfour --reset-then-reuse-values --set jvmReader.enabled=false
```

Helm removes the DaemonSet, its service account and NetworkPolicy, and the token Secrets the chart generated, and the agent stops reading JVMs. When the chart created the namespace (`jvmReader.createNamespace=true`), Helm deletes it too, with anything else in it. A namespace you created stays, and so does your PolicyException, until you delete them.

## Behind a proxy

The agent sends data to `api.levelfour.ai` on port 443. If the cluster reaches the internet through a proxy, set `HTTPS_PROXY` for the agent with `extraEnv`. Set `NO_PROXY` to your in-cluster addresses so the agent still reaches the kubelets and the API server directly: `.svc`, `.cluster.local`, the service CIDR, and the pod and node CIDRs.

```yaml title="values.yaml"
extraEnv:
  - name: HTTPS_PROXY
    value: http://proxy.example.com:3128
  - name: NO_PROXY
    value: .svc,.cluster.local,172.20.0.0/16,10.0.0.0/16
```

Replace the CIDRs with your cluster's. The API server's in-cluster address sits in the service CIDR. On Amazon EKS, read it with:

```bash
aws eks describe-cluster --name YOUR_EKS_CLUSTER \
  --query cluster.kubernetesNetworkConfig.serviceIpv4Cidr --output text
```

## Private registry mirror

To pull the agent from your own registry, copy the image there and point the chart at it. Copy both architectures (`linux/amd64` and `linux/arm64`) and keep the tag, because the chart pulls the tag that matches its version. `crane copy` copies every architecture by default; with `skopeo copy`, pass `--all`.

```bash
crane copy public.ecr.aws/levelfour/k8s-agent:0.8.6 registry.example.com/levelfour/k8s-agent:0.8.6
```

```yaml title="values.yaml"
image:
  repository: registry.example.com/levelfour/k8s-agent
imagePullSecrets:
  - name: registry-credentials
```

`registry-credentials` is a `kubernetes.io/dockerconfigjson` Secret in the `levelfour` namespace. To pin the exact image you [verified](#verify-the-signatures-and-sbom), set `image.digest` to the digest `crane digest public.ecr.aws/levelfour/k8s-agent:0.8.6` prints. `crane copy` keeps that digest.

To mirror the chart as well, pull it and push it to your registry, then install from `oci://registry.example.com/levelfour/charts/levelfour-agent`:

```bash
helm pull oci://public.ecr.aws/levelfour/charts/levelfour-agent --version 0.8.6
helm push levelfour-agent-0.8.6.tgz oci://registry.example.com/levelfour/charts
```

Verify the signatures on the public copies before you mirror them.

## Verify the signatures and SBOM

LevelFour signs every agent image and chart with cosign, and attaches an SPDX SBOM to each image as a signed attestation. The signing key stays in AWS KMS. Check a release with the LevelFour public key and cosign 3 or later.

Download the public key:

```bash
curl -sSfLO https://docs.levelfour.ai/keys/levelfour-k8s-agent.pub
```

Verify the image and the chart:

```bash
cosign verify --key levelfour-k8s-agent.pub public.ecr.aws/levelfour/k8s-agent:0.8.6
cosign verify --key levelfour-k8s-agent.pub public.ecr.aws/levelfour/charts/levelfour-agent:0.8.6
```

Verify the SBOM attestation:

```bash
cosign verify-attestation --key levelfour-k8s-agent.pub --type spdxjson public.ecr.aws/levelfour/k8s-agent:0.8.6
```

To save the SBOM itself, pipe that command's output through `jq -r .payload | base64 -d | jq .predicate > levelfour-agent-0.8.6.spdx.json`.

Each command exits with an error when the signature is missing or a different key made it.

### Verify the image your nodes run

The version tag points to the multi-arch index, and the SBOM on the tag lists the packages of the amd64 image. Releases after 0.2.0 also sign each architecture's image and attach an SBOM of its own packages, so you can check the exact image an arm64 or amd64 node pulls. List the digests:

```bash
docker buildx imagetools inspect public.ecr.aws/levelfour/k8s-agent:<version>
```

Then verify the digest listed for your nodes' platform, `linux/arm64` on Graviton:

```bash
cosign verify --key levelfour-k8s-agent.pub public.ecr.aws/levelfour/k8s-agent@sha256:<digest>
cosign verify-attestation --key levelfour-k8s-agent.pub --type spdxjson public.ecr.aws/levelfour/k8s-agent@sha256:<digest>
```

### Verify the chart in Flux

Flux 2.8 and later verify cosign 3 signatures, so Flux can check the chart on every pull. Put the public key in a Secret next to the OCIRepository. Flux reads every key in that Secret whose name ends in `.pub`, and the file name gives the key that name:

```bash
kubectl -n levelfour create secret generic levelfour-cosign-key \
  --from-file=levelfour-k8s-agent.pub
```

Then add `verify` to the OCIRepository from [Install with GitOps](/kubernetes/gitops#point-your-gitops-tool-at-the-chart). Flux refuses a chart that the LevelFour key did not sign:

```yaml title="levelfour-agent.yaml"
spec:
  verify:
    provider: cosign
    secretRef:
      name: levelfour-cosign-key
```
