Files
..

agent

gRPC agent that runs as a systemd service on each NVKE node. An orchestrator calls it to drive kubeadm lifecycle, package/CNI install, API encryption, and related node-local operations — without interactive SSH.

Doc Purpose
AGENTS.md Build, test, proto, versioning, and contributor conventions
docs/DESIGN.md Architecture and API surface
docs/SECURITY.md Security context (reporting: repo-root SECURITY.md)
pkg/agent/proto/node_agent.proto Canonical RPC definitions
config.env.example Build/runtime artifact endpoint knobs

Module: github.com/dsx-ai-factory/nvke/agent

Quick start

# From the monorepo root
./build/agent.sh test
./build/agent.sh build

# Or from this directory
make test
make build

Install a release tarball on a node (as root):

  1. Extract the package on the host
  2. Run scripts/agent-installer.sh (or the bundled installer from the release)
  3. Configure flags via /etc/default/nvke-agent (see below)

Configuration

Copy config.env.example → config.env (gitignored) for local build/publish overrides. On nodes, set flags via /etc/default/nvke-agent.

Important flags (also settable via env; see AGENT_ARGS):

Flag Notes
--bundle-server-url Optional. Bundle source for InstallBundle (https://, http://, file://, or oci://). Also NKE_BUNDLE_SERVER_URL. Prefer apt when unset.
--index-file-url Optional absolute index URL (NKE_BUNDLE_INDEX_URL); otherwise derived from the bundle server + OS
--cni-image-registry Optional OCI prefix for CNI helm global.registry (NKE_CNI_IMAGE_REGISTRY)
--disable-mtls Plaintext gRPC (development only)
--spiffe-socket-path SPIFFE workload API socket. Used for the gRPC server's mTLS unless --disable-mtls is set, and always by the SPIRE agent RPCs
--secure-server-port gRPC listen port (default 15005)
--control-plane-endpoint-gate-file Optional. Absolute path of the control plane endpoint gate file. Empty means no gate
--control-plane-endpoint-backend-interface Interface on which the connections of the load balancer arrive. Required with the gate file
--control-plane-endpoint-gate-settle Time between closing the gate and closing the established connections (default 10s)
--version Print build version and exit

Example:

# Apt-first (no bundle server required)
AGENT_ARGS="--disable-mtls"

# Optional: enable legacy HTTP/OCI bundle installs
AGENT_ARGS="--bundle-server-url https://artifacts.example.com/ --disable-mtls"
# OCI bundles:
# AGENT_ARGS="--bundle-server-url oci://registry.example.com/nvke/bundles --disable-mtls"

There is no built-in artifact host. When using bundles, consumers must point the agent at their own S3/HTTP or OCI layout. Index entries use paths relative to the bundle server URL (for example nke_bundles/Ubuntu_24.04/kubeadm_v1.30.0.tgz).

gRPC reflection is enabled on the same port (useful with grpcurl).

Control plane endpoint gate

A control plane node behind a load balancer that it does not run, for example a Service of another cluster, has no kube-vip to withdraw. With --control-plane-endpoint-gate-file set, the agent withdraws such a node through a gate file. With no gate file it withdraws only kube-vip.

On StartK8sControlPlaneNodeGracefulShutdown and StartEtcdDefrag the agent creates the gate file, waits the settle time, closes the established connections of remote clients on the IPv4 address of the backend interface and port 6443 (ss -K), and checks for 30 seconds that no new connection arrives there. A new connection fails the withdrawal. StartKubeVipRestore removes the gate file. A node with kube-vip and a gate leaves both, the gate first.

KubeadmUpgradeApply withdraws the node through the gate in the same way, after kubeadm upgrade plan and before kubeadm upgrade apply, which restarts etcd and the API server of the node. It removes the gate file when kubeadm upgrade apply returns, also when that command fails. A withdrawal that fails stops the call before kubeadm upgrade apply. This call does not withdraw kube-vip.

The call removes only a gate file that it wrote. It writes the file when the gate is open, and when the file names the agent as the one that opens the gate. A gate that a caller closed stays closed during the call and after it, until the caller opens it with StartKubeVipRestore. The call then waits no settle time and closes no connection.

On a cluster with one control plane node, which the agent reads as one voting member of etcd, the call does not use the gate: kubeadm reaches the cluster through the load balancer, and no other node is behind it. The call does not use the gate either when the agent cannot list the members of etcd. In both cases it creates no gate file, and it leaves a gate file that exists as it is.

Other calls that restart the API server, such as the certificate renewal, do not touch the gate. Their caller closes it first with StartK8sControlPlaneNodeGracefulShutdown and opens it with StartKubeVipRestore.

The agent cannot see the load balancer, so the deployment has to provide:

  • A health check that fails while the gate file exists, and that passes only when the file is gone and /readyz of the local API server answers 200. It must not connect to the backend address from another host.
  • A backend interface that carries only the connections of the load balancer. Clients in the cluster reach the API server on another address.
  • One global IPv4 address on the backend interface. IPv6 is not handled.
  • A kernel with INET_DIAG, INET_TCP_DIAG and INET_DIAG_DESTROY. Without them ss -K closes nothing and reports no error. The withdrawal then fails at the check for new connections, which also sees a connection that stayed.
  • A settle time longer than the health check needs to take the node out.
  • A folder for the gate file that only root can write to. A user who can write to that folder can close and open the gate without the agent. The agent does not check the folder.

The content of the gate file says who opens the gate:

  • /etc/kubernetes/manifests-backup: a caller, with StartKubeVipRestore. The gate stays closed until then, also over a restart of the agent. Over a reboot of the node it stays closed only when the gate file is on a path that the reboot does not clear.
  • /etc/kubernetes/manifests-backup/etcd-defrag: the agent, at the end of the defragmentation or at its next start.
  • kubeadm-upgrade-apply: the agent, when kubeadm upgrade apply returns or at its next start.
  • Other content, such as a file made by hand: a caller.

Logs

Path Purpose
/var/log/nvke-agent-audit.log Audit log (--audit-log-file); records are also mirrored to the service journal
/var/log/nvke-execute-scripts.log ExecuteScript / StreamExecuteScript results
journalctl -u nvke-agent Service journal

GetSupportBundle returns a tarball with state, journals, and related diagnostics.

Core capabilities

  • Kubeadm: init, join, reset, preflight, join strings, kubeconfig
  • CNI: InstallCNI after packages are present; prefer noCniInstall: true on init for new orchestration (legacy in-init CNI remains when noCniInstall is false)
  • Packages / collections: apt packages, apt repos, bundles, collections
  • Encryption: Kubernetes API/etcd encryption-at-rest
  • Control-plane ops: graceful shutdown / kube-vip restore, apiserver manifest patch
  • Utilities: script execution, file upload, support bundle

Full RPC list: pkg/agent/proto/node_agent.proto and docs/DESIGN.md.

Example: create a small cluster (grpcurl)

Examples below use obviously fake tokens, hashes, and keys so scanners do not treat them as live credentials. Replace with values from your environment.

# Init first control-plane (TEST-NET address 192.0.2.10 is documentation-only)
grpcurl -plaintext -d '{
  "podNetworkCidr": "10.244.0.0/16",
  "serviceCidr": "10.96.0.0/12",
  "noCniInstall": true
}' 192.0.2.10:15005 proto.NodeAgent.ExecuteKubeadmInit

# Poll status / join strings
grpcurl -plaintext 192.0.2.10:15005 proto.NodeAgent.GetKubeadmStatus
grpcurl -plaintext 192.0.2.10:15005 proto.NodeAgent.GetKubeadmJoinString

# Join another node (placeholders — not real kubeadm material)
grpcurl -plaintext -d '{
  "kubeadmJoinString": "join 192.0.2.10:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:0000000000000000000000000000000000000000000000000000000000000000 --control-plane --certificate-key 0000000000000000000000000000000000000000000000000000000000000000"
}' 192.0.2.11:15005 proto.NodeAgent.ExecuteKubeadmJoin

Install CNI after packages are on the control-plane host (InstallPackages), then:

grpcurl -plaintext -d '{
  "cniVariant": "CNI_VARIANT_OVN",
  "podNetworkCidr": "10.244.0.0/16",
  "serviceCidr": "10.96.0.0/12"
}' 192.0.2.10:15005 proto.NodeAgent.InstallCNI

More sample clients and manifests: samples/ and sample-clients/.

Encryption (sketch)

API encryption is a multi-step flow; see DESIGN.md and the proto comments. When posting example keys in docs or tickets, use clearly invalid material, e.g.:

encryptionKey: "EXAMPLEONLY_not-a-real-secretbox-key_000000000000="

Never paste production tokens, certificate keys, or encryption keys into the README.

mTLS

Production should use SPIFFE mTLS (default). --disable-mtls is for local/dev only. Clients need a matching SPIFFE identity (path prefix /nke-service/).

Build notes

make build          # linux/amd64 + linux/arm64
make package        # release tarballs under release/
make protos         # regenerate *.pb.go via buf
make setup-hooks    # monorepo-aware proto pre-commit hook

Version comes from git describe --tags --always --dirty --match 'v*', the repository's release tags (see AGENTS.md). Override with VERSION=... when needed.

Get the agent

The supported way to obtain the agent is to build it from source: make -C agent package for the release tarballs, or make -C agent deb-amd64 (deb-arm64) for the Debian package. Prebuilt agent binaries and packages in GHCR, NVCR and the apt intake are private internal artifacts today, not public downloads.

The reference OS image (os-image/) installs the .deb built from this checkout. The package spec and maintainer scripts live in os-image/packages/nvke-agent/packaging/; make -C agent deb-amd64 or deb-arm64 builds it with the shared pinned nfpm.

Internal maintainer publication

The publication pipeline's artifacts are private today. Its registries and apt intake are not a supported download path for external users. Maintainers can find the tag triggers, destinations and publication controls in the artifact publication reference.

Every commit on main and every vX.Y.Z release tag publishes the binaries to GHCR as OCI artifacts, joined by a multi-arch index (.github/workflows/agent-artifact.yml). Tags are edge, sha-<commit>, and vX.Y.Z, each with -amd64 / -arm64 single-platform variants underneath. A release tag gets the vX.Y.Z tag unless NVKE_GITHUB_PUBLISH leaves out agent; the sha-<commit> tag is pushed either way. These are binaries, not container images: the layer is the executable itself, so docker pull is not the way in.

Every vX.Y.Z and vX.Y.Z-beta.N tag also builds native amd64 and arm64 .debs, uploads them to the apt-publisher S3 intake (.github/workflows/agent-deb-publish.yml, via scripts/upload-s3-apt-intake.sh) and pushes them to NVCR. A vX.Y.Z tag also pushes them to GHCR unless NVKE_GITHUB_PUBLISH leaves out agent. A beta does not enter the intake's index.json. Main merges and branch workflow runs do not ingest — only refs/tags/v*.

The intake destination comes from the GitHub apt-intake environment (APT_INTAKE_S3_URI, APT_INTAKE_AWS_ROLE_ARN, …) — nothing bucket-specific is committed here. Once apt-publisher is pointed at that intake, cut over from the previous GitLab package source.