Skip to content

K8s Agent Reference

The Shoehorn K8s Agent is a lightweight, push-based agent that discovers Kubernetes workloads and syncs them to the Shoehorn catalog. It runs inside each cluster you want to monitor.

For operational considerations and installation, see K8s Agent.

Kubernetes Cluster
├── Watcher (client-go informers)
│ ├── Deployments, StatefulSets, DaemonSets
│ ├── CronJobs, Jobs, Services, Ingresses, Pods
│ ├── Events, Namespaces, NetworkPolicies
│ └── Filters: namespace, label selector, annotations
│
├── GitOps Watcher (optional)
│ ├── ArgoCD Applications
│ ├── FluxCD Kustomizations, HelmReleases
│ └── Event cache (max 20 events, last 1h)
│
├── Metrics Collector (optional)
│ ├── Samples metrics-server every 5m
│ ├── 7-day rolling window (p95, max, avg)
│ └── Graceful degradation if unavailable
│
├── Batcher
│ ├── Time-based flush: every 30s
│ ├── Size-based flush: at 100 events
│ └── 2000-event channel buffer
│
├── Pusher
│ ├── POST /api/v1/k8s/agents/push
│ ├── Circuit breaker (5 failures, 60s recovery)
│ ├── Retry with exponential backoff (3 attempts)
│ └── Max payload: 10MB
│
├── Heartbeat
│ └── POST /api/v1/k8s/agents/heartbeat (every 5m)
│
└── Leader Election (HA mode)
├── Kubernetes Leases (coordination.k8s.io)
└── Only leader runs watchers and pushers

All settings are environment variables prefixed with SHOEHORN_.

Variable Description
SHOEHORN_API_ENDPOINT Shoehorn API URL
SHOEHORN_API_TOKEN Agent bearer token (from cluster registration)
SHOEHORN_CLUSTER_ID Unique cluster slug (lowercase, hyphens allowed)
SHOEHORN_CLUSTER_NAME Display name (defaults to cluster ID)
Variable Default Range Description
SHOEHORN_BATCH_INTERVAL 30s 1s-10m Event batch flush interval
SHOEHORN_BATCH_SIZE 100 1-10000 Max events per batch
SHOEHORN_PUSH_RETRIES 3 0-10 Retry attempts on push failure. Pushes of the startup full sync are retried until Shoehorn accepts them
SHOEHORN_PUSH_TIMEOUT 30s 1s-5m HTTP timeout for push
SHOEHORN_FULL_SYNC_MAX_WAIT 15m 1m-24h How long the startup full sync may wait for Shoehorn before it gives up and withholds its completion
SHOEHORN_HEARTBEAT_INTERVAL 5m 1m-30m Heartbeat frequency
SHOEHORN_HEALTH_PORT 8080 - Health check server port
SHOEHORN_LOG_LEVEL info debug/info/warn/error Log verbosity
SHOEHORN_LOG_FORMAT json json/console Log output format
Variable Default Description
SHOEHORN_NAMESPACES : (all) Whitelist (comma-separated)
SHOEHORN_EXCLUDE_NAMESPACES - Blacklist (comma-separated)
SHOEHORN_LABEL_SELECTOR - Kubernetes label selector
SHOEHORN_WATCHED_KINDS - Specific resource kinds
Variable Default Description
SHOEHORN_ANNOTATION_DEFAULT_BEHAVIOR monitor-all monitor-all, require-annotation, monitor-none
SHOEHORN_ANNOTATION_DEFAULT_LEVEL full Default monitoring level

Per-resource annotation: shoehorn.dev/monitoring-level

Level Collected Data
basic Workload status, replicas, image info
detailed Basic + restart counts, container states, pod conditions
full (default) Detailed + CPU/memory requests/limits, QoS class

All levels read from the pod the agent already watches, so a higher level adds no extra API calls, only a slightly larger payload. Live CPU/memory usage is separate (see Metrics Collection below) and needs metrics-server.

Variable Default Range Description
SHOEHORN_METRICS_SAMPLE_INTERVAL 5m 1m-30m Metrics-server sample rate
SHOEHORN_METRICS_WINDOW_HOURS 168 (7d) 1-720 Rolling window size in hours
Variable Default Description
SHOEHORN_GITOPS_TOOL : (disabled) argocd or fluxcd
SHOEHORN_GITOPS_ARGOCD_NAMESPACE argocd ArgoCD install namespace
SHOEHORN_GITOPS_ARGOCD_SERVER_URL - ArgoCD server URL (for UI links)
SHOEHORN_GITOPS_ARGOCD_TOKEN - ArgoCD API token
SHOEHORN_GITOPS_WATCH_ALL_NAMESPACES false Watch GitOps CRDs cluster-wide
SHOEHORN_GITOPS_COMMAND_POLL_INTERVAL 30s Command polling frequency

The Helm chart creates a ClusterRole with these permissions:

# Workloads
- apiGroups: ["apps"]
resources: [deployments, statefulsets, daemonsets]
verbs: [get, list, watch]
# Batch
- apiGroups: ["batch"]
resources: [cronjobs, jobs]
verbs: [get, list, watch]
# Core resources
- apiGroups: [""]
resources: [namespaces, pods, services, events]
verbs: [get, list, watch]
# Networking
- apiGroups: ["networking.k8s.io"]
resources: [ingresses, networkpolicies]
verbs: [get, list, watch]
# Cilium (if present)
- apiGroups: ["cilium.io"]
resources: [ciliumnetworkpolicies, ciliumclusterwidenetworkpolicies]
verbs: [get, list, watch]
# Metrics
- apiGroups: ["metrics.k8s.io"]
resources: [pods]
verbs: [get, list]
# Leader election
- apiGroups: ["coordination.k8s.io"]
resources: [leases]
verbs: [get, list, watch, create, update, patch]
- apiGroups: ["argoproj.io"]
resources: [applications]
verbs: [get, list, watch]
- apiGroups: ["kustomize.toolkit.fluxcd.io"]
resources: [kustomizations]
verbs: [get, list, watch, patch]
- apiGroups: ["helm.toolkit.fluxcd.io"]
resources: [helmreleases]
verbs: [get, list, watch, patch]
- apiGroups: ["source.toolkit.fluxcd.io"]
resources: [gitrepositories, helmrepositories]
verbs: [get, list, watch]

The agent infers team ownership for discovered workloads, checked in this order:

  1. Annotation shoehorn.dev/team on the workload
  2. Annotation shoehorn.dev/owner on the workload
  3. Label owner on the workload
  4. Label shoehorn.dev/team on the namespace
  5. Namespace name pattern extraction (e.g., payments-prod -> payments)
  6. Default: unassigned

Label namespaces for zero-config team assignment:

Terminal window
kubectl label namespace payments shoehorn.dev/team=payments-team
Annotation Description
shoehorn.dev/monitor true/false - opt in or out of monitoring
shoehorn.dev/monitoring-level basic, detailed, or full
shoehorn.dev/team Team slug for ownership
shoehorn.dev/owner Alternative to shoehorn.dev/team
shoehorn.dev/entityFile Path to .shoehorn/catalog.yaml for entity enrichment

See Annotations Reference for the complete list.

Endpoint Purpose
/healthz Liveness probe (checks leader eligibility)
/readyz Readiness probe (checks leader status + push health)
/livez Live status
/metrics Prometheus metrics

See Agent Health for the full readiness model.

For production clusters, run 2-3 replicas with leader election:

replicaCount: 3
leaderElection:
enabled: true
podDisruptionBudget:
minAvailable: 2

Only the leader runs watchers and pushes data. Followers are hot standbys that pass readiness probes and take over within seconds if the leader dies.

  • Read-only RBAC – no create/update/delete on workloads
  • Non-root container – runs as UID 1000, drops all capabilities
  • Read-only filesystem – readOnlyRootFilesystem: true
  • HTTPS enforced – warns if API endpoint uses http://
  • Token redaction – API token cannot appear in logs or traces
  • No redirect following – prevents bearer token leakage
  • Annotation sanitization – strips kubectl.kubernetes.io/last-applied-configuration

Past roughly 200 nodes or 5000 pods, the agent’s default buffers can drop events during deploy waves or informer resyncs. Two metrics tell you when that happens:

Metric Meaning Fix
shoehorn_k8s_watcher_events_dropped_total Event buffer overflowed Raise agent.eventChannelSize and agent.rateLimit
shoehorn_batcher_batches_dropped_total Push pipeline fell behind Raise agent.batchChannelSize

Dropped events aren’t lost for good: the next resync reconciles state. But a climbing counter means your dashboard lags reality, so fix it.

The startup full sync is the exception. Its workloads and pods wait for room in these buffers instead of being dropped, and the agent keeps retrying until Shoehorn has the whole list, so the buffers no longer decide whether it completes. Memory is what grows with the cluster, because the agent keeps a copy of every object it watches. In a test with Deployments and pods the size of a test cluster’s, a startup list of 20,000 completed in 15 seconds, with Shoehorn unreachable for the first 12. Afterwards the agent’s Go heap held about 15 MiB per 1,000 objects. During the list it peaked at about 30 MiB per 1,000: about 600 MiB at 20,000, or about 740 MiB with connected resources on across 200 namespaces. Container memory runs above the Go heap. Size the memory limit from your cluster’s object count: the chart’s default of 150Mi is too small for a large cluster, and the 512Mi of the large-cluster preset below is too small at 20,000 objects.

While Shoehorn is unreachable, memory also grows with every change in the cluster: about 64 MiB a minute at 50 pod updates a second, in the same test. The startup list gives up after agent.fullSyncMaxWait (15 minutes by default), which bounds that growth. On a cluster with a lot of churn and a tight memory limit, lower it.

With connected resources on, each push also reads the objects its workloads use: about 7 Kubernetes API calls for every namespace in the push, plus 2. The calls run one at a time, so a push also waits for every response.

The agent makes at most agent.kubernetes.apiQPS calls a second (default 50), with bursts up to agent.kubernetes.apiBurst (default 100). This is separate from agent.rateLimit, which limits how many watched events a second enter the agent.

On clusters with many namespaces, raise both, so a large push finishes quickly, and within the 20 seconds the agent has to send its last changes when it stops. The API server’s priority and fairness still protect the server.

Start from the bundled preset instead of tuning by hand:

Terminal window
helm install shoehorn-k8s-agent oci://ghcr.io/shoehorn-dev/helm-charts/shoehorn-k8s-agent \
-f https://raw.githubusercontent.com/shoehorn-dev/helm-charts/main/shoehorn-k8s-agent/examples/values-large-cluster.yaml \
--set shoehorn.apiURL=https://shoehorn.example.com \
--set shoehorn.apiToken=shp_agent_xxxxxxxxxxxx \
--set shoehorn.cluster.id=my-large-cluster

By default the agent watches the whole cluster and filters in memory. Set agent.kubernetes.scopeMode: namespaces to scope the watch itself: the agent only requests the listed namespaces from the API server, runs with namespace-scoped RBAC, and never receives objects outside its scope.

Use it when teams on a shared cluster must not be visible to each other’s agents, or when your security policy rules out cluster-wide read access.

Two things change in scoped mode:

  • Cluster-wide Cilium policies (CiliumClusterwideNetworkPolicy) aren’t watched, since they’re cluster-scoped by definition. Namespaced policies still work.
  • Each scoped install registers as its own cluster in Shoehorn and uses one license slot.

See examples/values-scoped.yaml in the chart for a working setup.