Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

In Kubernetes

See what a node’s media driver is publishing: ergo-aeron in a pod on that node, reading the driver’s directory through a read-only mount. It starts no Aeron client and adds no subscription (why). The files are in k8s/ergo-aeron.

The driver’s directory isUse
a hostPaththe DaemonSet and kubectl aeron
an emptyDir, and you can edit the driver poda sidecar
an emptyDir, pod left as it is, driver’s uid knownkubectl debug on the driver pod
an emptyDir, and you may run a root pod on the nodekubectl debug node/

Set up

# From a checkout. No JDK is needed: the image has no archive control reader.
docker build -f k8s/ergo-aeron/Dockerfile -t REGISTRY/ergo-aeron:TAG .
docker push REGISTRY/ergo-aeron:TAG          # or: kind load docker-image ...

kubectl create namespace ergo-aeron
kubectl -n ergo-aeron create configmap ergo-aeron-schemas --from-file=schemas/
# Set the image, hostPath, AERON_DIR and nodeSelector first.
kubectl apply -f k8s/ergo-aeron/daemonset.yaml

install -m 755 k8s/ergo-aeron/kubectl-aeron ~/.local/bin/   # any directory on PATH

Use

kubectl aeron nodes                      # the ergo-aeron pod of each node
kubectl aeron health                     # every node, or `health NODE`
kubectl aeron tui NODE                   # the terminal UI
kubectl aeron streams NODE               # or counters, errors, loss, driver, log
kubectl aeron messages NODE --stream 1001 --schema /schemas/trade.xml --follow

health exits 0 (OK or WARN), 1 (ALARM) or 2 (unreadable, timed out, or no running viewer pod); kubectl exec itself failing also exits 1. Anything after the node goes to ergo-aeron (subcommands). ERGO_AERON_NAMESPACE names another namespace.

From a terminal, Ctrl-C stops a --follow. With no terminal (a pipe, a script) Kubernetes leaves the process running in the pod after kubectl has gone, and it keeps cnc.dat and the stream’s log file open: after a driver restart that is /dev/shm space the node does not get back until it ends. The plugin ends such a run after ERGO_AERON_TIMEOUT seconds (default 600). A bare kubectl exec has no such bound; kubectl -n ergo-aeron delete pod POD clears what is left.

Schemas reach the pod either way:

Way--schema
the ergo-aeron-schemas ConfigMap (at most 1 MiB, optional)/schemas, or one file in it
kubectl cp trade.xml ergo-aeron/POD:/tmp/trade.xml (gone with the pod)/tmp/trade.xml

From another machine

From your machineNeeds
ssh -t SERVER 'kubectl aeron tui NODE'kubectl, the plugin and a kubeconfig on SERVER, all found by a non-interactive ssh command. -t gives the terminal UI its terminal
ssh -N -L PORT:127.0.0.1:PORT SERVER, then kubectl aeron ... as usualkubectl, the plugin and a copy of the kubeconfig on your machine

The second is for an API server that listens only on SERVER’s loopback, as kind’s does by default. PORT is the one in the kubeconfig’s server: https://127.0.0.1:PORT, and must be free on your machine; the kubeconfig is used unchanged:

ssh SERVER 'cat KUBECONFIG_FILE' > kind.kubeconfig   # the one kind wrote on SERVER
chmod 600 kind.kubeconfig       # it is the cluster's admin credential
grep server: kind.kubeconfig    # https://127.0.0.1:PORT
ssh -N -L PORT:127.0.0.1:PORT SERVER &
KUBECONFIG=kind.kubeconfig kubectl aeron tui NODE

What goes in the pod and on the node

SettingWhy
PodhostPath of the parent of the driver’s directory, readOnly: true; AERON_DIR names the driver’s directory under ita driver that deletes and recreates its directory (aeron.dir.delete.on.start) leaves a mount of the directory itself pointing at the deleted one
PodhostPath type: DirectoryDirectoryOrCreate would create it owned by root, which a non-root driver cannot write
PodCPU request without a matching limit: QoS Burstableit runs on the shared CPUs and takes no exclusive CPU
Podnon-root, drop: [ALL], read-only root filesystemreading needs nothing else
Driver podits aeron.dir inside a hostPath shared with this DaemonSetanother pod cannot see an emptyDir
Nodethe parent directory exists and the driver’s uid can write it
NodenodeSelector in the DaemonSet picks the driver nodeson a node without the directory the pod stays ContainerCreating

Never mount /dev/shm itself as the parent. Aeron’s default directory, /dev/shm/aeron-USER, sits directly under it, and mounting it would show the viewer every process’s shared memory on the node. Give drivers a directory of their own (aeron.dir=/dev/shm/aeron/driver). Whoever can kubectl exec into the viewer can read everything under the mounted parent.

The namespace must allow hostPath volumes: the Pod Security baseline and restricted levels refuse them.

File permissions

Aeron’s C driver creates its files through its umask. The viewer must be able to read them:

Driver umaskFiles others can readThe viewer needs
022yesnothing: any uid
027its groupsupplementalGroups: [DRIVER_GID]
077norunAsUser: DRIVER_UID

A viewer that cannot read them is not told Permission denied: it says cannot read the Aeron driver ... Timed out waiting for CnC file, the same as for a directory with no driver. Compare ls -ln of the driver’s directory (kubectl exec into the driver pod) with the viewer’s id. Running as the driver’s own uid makes the files writable by ownership, and the read-only mount still refuses every write (Read-only file system).

A read-only mount is also why the one write action, driver terminate, does not work here.

Sidecar sharing an emptyDir

A second container in the driver pod, with the driver’s volume mounted read-only. No hostPath and no capability. In the pod spec:

containers:
  - name: driver   # as before, plus:
    volumeMounts: [{name: aeron, mountPath: /aeron}]    # aeron.dir=/aeron/driver
  - name: ergo-aeron
    image: REGISTRY/ergo-aeron:TAG
    env: [{name: AERON_DIR, value: /aeron/driver}]
    resources: {limits: {cpu: 100m, memory: 128Mi}}
    securityContext:
      runAsUser: 65534    # or the driver's uid: see File permissions
      runAsGroup: 65534
      runAsNonRoot: true
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities: {drop: [ALL]}
    volumeMounts:
      - {name: aeron, mountPath: /aeron, readOnly: true}
      - {name: tmp, mountPath: /tmp}    # for `kubectl cp` of schemas
volumes:
  - {name: aeron, emptyDir: {medium: Memory, sizeLimit: 256Mi}}
  - {name: tmp, emptyDir: {sizeLimit: 16Mi}}
kubectl exec -it DRIVER_POD -c ergo-aeron -- env TERM="$TERM" ergo-aeron --no-history
  • A Guaranteed pod stays Guaranteed only if every container’s requests equal its limits; the limits-only block above does that. A fractional CPU leaves the container in the shared CPU pool.
  • Not for a pod labelled ergon.io/latency: hot: the latency pod policy wants whole CPUs, among other things, from every container. Give that driver a hostPath and use the DaemonSet.
  • kubectl aeron does not find it: it looks only for the DaemonSet’s pods.

kubectl debug on the driver pod

An ephemeral container beside the running driver, which is not restarted. It shares the driver container’s processes, so the driver’s own filesystem, emptyDir mounts included, is at /proc/1/root/ (pid 1 being the driver container’s first process).

echo '{"securityContext":{"runAsUser":DRIVER_UID,"runAsGroup":DRIVER_GID}}' > user.json
kubectl debug DRIVER_POD --target=DRIVER_CONTAINER --image=REGISTRY/ergo-aeron:TAG \
    --profile=restricted --custom=user.json -c ergo-aeron -- sleep 3600
kubectl exec -it DRIVER_POD -c ergo-aeron -- env TERM="$TERM" ergo-aeron \
    --no-history --aeron-dir /proc/1/root/PATH/TO/AERON_DIR

What it takes to read /proc/1/root, for a driver container that adds no capabilities:

Debug container runs asDriver not rootDriver root
the driver’s uid and gid, no capabilityworks—
root with SYS_PTRACE (kubectl’s default profile, if nothing sets a uid)worksnot needed
root without SYS_PTRACE (--profile=netadmin)refusedworks
another non-root uidrefused—
  • For a root driver, leave out --profile and --custom.
  • A pod-level runAsUser applies to the debug container too.
  • Namespaces enforcing Pod Security baseline or restricted refuse SYS_PTRACE, which the default profile adds even with --custom; the command above passes both levels.
  • Refused reads show as cannot read the Aeron driver, not Permission denied.
  • The mount here is not read-only: as the driver’s uid or root, the container can write the driver’s files.

kubectl debug node/

For a driver whose directory is an emptyDir, or a node without the DaemonSet:

uid=$(kubectl get pod DRIVER_POD -o jsonpath='{.metadata.uid}')
node=$(kubectl get pod DRIVER_POD -o jsonpath='{.spec.nodeName}')
kubectl debug node/$node --image=REGISTRY/ergo-aeron:TAG --profile=general -- sleep 3600
# It prints the debug pod's name, node-debugger-NODE-xxxxx.
# No subcommand opens the terminal UI; or add streams, health, ...
kubectl exec -it node-debugger-NODE-xxxxx -- env TERM="$TERM" ergo-aeron \
    --aeron-dir "/host/var/lib/kubelet/pods/$uid/volumes/kubernetes.io~empty-dir/VOLUME"
kubectl delete pod node-debugger-NODE-xxxxx

VOLUME is the emptyDir’s name in the driver pod, followed by the driver directory’s path inside it, if any. Copy schemas in with kubectl cp.

  • The node’s filesystem is mounted at /host writable, and the pod runs as root: nothing but the tool’s own read-only behaviour protects the driver. Run nothing else there, and delete the pod when done.
  • The pod sees the mounts that existed when it started. A memory-backed emptyDir made later (a restarted driver pod) needs a new debug pod.

Check it

k8s/ergo-aeron/e2e.sh builds the image and, on a throwaway kind cluster, checks the health exit codes, reading and decoding, the three umasks, a driver restart, the time limit and Ctrl-C, refused writes and kubectl debug node/. It needs Linux with docker (and buildx), kind, kubectl and script, and has run on x86-64 with kind 0.33.0. The sidecar, driver-pod kubectl debug and other-machine sections are not part of it; they were run by hand on the same kind version with Kubernetes 1.37.