Susan

nexusadm

Homelab

nexusadm administers the Kubernetes cluster of the homelab setup: it adds, removes and restarts nodes, upgrades their packages, grants and revokes accesses (cluster accounts with limited rights and a fixed duration; see the glossary), stores secrets in the desktop keyring, reads the API audit log and checks the health of each node. Day-to-day cluster commands go through nexusctl and nexushelm, which use the accesses that nexusadm creates. Every action that adds rights, reads a keyring secret or changes the nodes opens a confirmation window on your desktop session (see Confirmation window), and every subcommand except log and node remove --dry-run writes to the journal once its arguments are valid. Messages and table headers are printed in French.

Synopsis

nexusadm node list
nexusadm node add <name> <ip>
nexusadm node remove [--dry-run] <name>
nexusadm node reboot <name>
nexusadm cluster upgrade [--ansi auto|always|never]
nexusadm grant
nexusadm grant request <access> [--preset read-only] [--rule <scope>:<resources>[/<name>]:<verbs>]...
                                [--port-forward <namespace>]... [--secret <reference>]...
                                [--duration 10m..168h] [--holder <holder>] [--reason <text>] [--allow-sensitive]
nexusadm grant extend <access> [--rule ...]... [--port-forward <namespace>]... [--secret <reference>]...
                               [--reason <text>] [--allow-sensitive]
nexusadm grant list
nexusadm grant show <access>
nexusadm grant revoke <access> | --all
nexusadm secret add|show|rm <name>
nexusadm audit [--since 24h] [--json]
nexusadm doctor [--fix]
nexusadm log [-n N] [--json]

Without arguments, with --help or with an unknown subcommand, nexusadm prints its usage line and exits with code 2.

Common exit codes

CodeMeaning
0Success.
1A step failed: kubectl, SSH, the keyring, or the journal could not be written. Also returned by audit and doctor when they report something to examine.
2Invalid argument or usage error. Nothing is changed.
3The action was refused in the confirmation window.
4The confirmation window could not open or received no answer. No decision was taken.

node add returns the exit code of ansible-playbook.

node list: list the nodes

nexusadm node list

Prints one line per node of the cluster: name, state (Ready or NotReady), kubelet version, internal IP, and whether the node is declared in the Ansible inventory. A node declared in the inventory but missing from the cluster appears as absent du cluster. The command uses the access named by NEXUSCONFIG, read by default, and opens no window. Without that access, it exits with code 1 and suggests nexusadm grant.

node add: add a node

nexusadm node add <name> <ip>
ArgumentConstraint
<name>Lowercase letters and digits only.
<ip>An IPv4 address.

After confirmation, the command writes inventory/noeud-<name>.yml in the Ansible folder, with the next free WireGuard address from 192.168.77.11. An existing file with the placeholder A_RENSEIGNER receives the address; an existing file with another address stops the command. It then runs ansible-playbook playbooks/site.yml --limit microk8s, on every node of the group, so the firewall of the existing nodes accepts the new one. The playbook installs WireGuard and MicroK8s and joins the node to the cluster.

nexusadm node add node2 192.168.1.12

node remove: remove a node

nexusadm node remove [--dry-run] <name>
OptionEffect
--dry-runPrints the planned steps and exits with code 0. No window, no journal entry.

The node must be declared in the inventory with an address, and the primary node (microk8s_primary in inventory/group_vars/microk8s/main.yml) must be known. The primary node itself cannot be removed: change microk8s_primary first. After confirmation, the command runs five steps and stops at the first failure with code 1:

  1. Drain the node (kubectl drain --ignore-daemonsets --delete-emptydir-data --timeout=180s).
  2. Run microk8s leave on the node.
  3. Run microk8s remove-node <ip> --force on the primary node.
  4. Delete the Kubernetes Node object.
  5. Delete the inventory file of the node.

Data in the local volumes of the node is not moved.

nexusadm node remove --dry-run node2

node reboot: restart a node

nexusadm node reboot <name>

The command reads the state of every node first. If another node is not Ready, it exits with code 1: with three nodes, losing two breaks the dqlite quorum. After confirmation, it schedules systemctl reboot on the machine three seconds later and returns. Follow the return of the node with nexusadm doctor.

nexusadm node reboot node2

cluster upgrade: upgrade the packages of every node

nexusadm cluster upgrade [--ansi auto|always|never]
OptionDefaultEffect
--ansiautoalways draws a progress table redrawn in place, never prints one line per step. auto draws the table only when the output is a terminal and TERM is not dumb. Any other value exits with code 2.

cluster update is accepted as a synonym. The command handles the nodes of the inventory one at a time, in alphabetical order, the primary node last. After one confirmation for the whole run, for each node it:

  1. checks that the node and every other node are Ready;
  2. drains the node (timeout 300 s);
  3. runs apt-get update then apt-get upgrade, keeping existing configuration files;
  4. restarts the machine if /var/run/reboot-required exists, then waits up to 15 minutes for the node to come back Ready with a new boot ID;
  5. uncordons the node.

The first failure stops the command with code 1. A node that was drained stays cordoned; check it with nexusadm doctor. Only apt packages are upgraded: the MicroK8s snap and firmware are not.

nexusadm cluster upgrade --ansi never

grant: create the read-only access

nexusadm grant

Equivalent to nexusadm grant request read --preset read-only. read is the access that nexusctl and nexusadm node list use by default.

grant request: create an access

nexusadm grant request <access> [options]

The access name has 2 to 40 characters: lowercase letters, digits and hyphens, starting with a letter and ending with a letter or a digit. The request needs at least one --preset, --rule or --secret.

OptionRepeatableValue
--preset read-onlyNoRead (get, list, watch) on the whole cluster: the Kubernetes view role, which excludes Secrets, plus nodes, persistent volumes, storage classes, ingress classes, custom resource definitions and the Prometheus resources of monitoring.coreos.com. read-only is the only preset.
--rule <scope>:<resources>:<verbs>YesOne RBAC rule. See the rule syntax below.
--port-forward <namespace>YesThe rights of nexusctl port-forward in one namespace: get and list on pods and services, create on pods/portforward. * is not accepted.
--secret <reference>YesA secret that nexusctl may resolve by reference: <namespace>/<name>#<key> for a cluster Secret, keyring/<name> for a keyring secret, with or without the SECRET: prefix. A cluster reference adds get on that one Secret.
--duration <d>NoToken lifetime, from 10m to 168h. Default 8h, or 1h for an access that touches Secrets.
--holder <holder>NoWho uses the access: up to 63 letters, digits, spaces, dots, underscores or hyphens.
--reason <text>NoWhy the access is requested: 1 to 200 characters on one line, shown in the window.
--allow-sensitiveNoRequired to submit a sensitive request. See below.

Rule syntax

<scope>:<resources>:<verbs>, for example nexus-system:pods,services:get,list.

PartValue
<scope>A namespace, or * for the whole cluster. The namespace must exist, or the command exits with code 1 before the window opens.
<resources>Comma-separated resources. The API group follows a dot: deployments.apps. * means every resource.
<verbs>Comma-separated, among get, list, watch, create, update, patch, delete, deletecollection, escalate, bind, impersonate and *.

A /<name> suffix limits the rule to one object (Kubernetes resourceNames), for example *:clusterroles.rbac.authorization.k8s.io/nexus-operator:escalate,get. A named rule has one resource, never *, and neither create nor deletecollection, which Kubernetes does not limit by name; write those in a separate rule. In a rule, either every resource carries a name or none does.

Sensitive requests

A request is sensitive when one of its rules:

Secrets of a single namespace, without object names and with the verbs Helm uses (get, list, watch, create, update, patch, delete), are not sensitive: the window shows a notice, and nexusctl and nexushelm mask their values in their output. The --preset, --port-forward and --secret options are never sensitive by themselves.

Without --allow-sensitive, a sensitive request exits with code 2 and lists the reasons. With it, the window shows a warning, and its Autoriser button stays inactive until you tick the box “Je comprends ces droits et je les accorde.”

Time limit of accesses that touch Secrets

An access touches Secrets when a rule names secrets or * as a resource, or when it carries a cluster --secret reference. Such an access lasts 1 hour at most: without --duration it gets 1 hour, and a longer --duration exits with code 2. Keyring references do not count.

Steps

  1. The command deletes the expired accesses.
  2. A first window shows the command, the folder, the account nexus-<access>, the holder, the reason, the rights granted and the manifest that is applied.
  3. A second window offers durations up to the one requested (10 minutes, 30 minutes, 1, 2, 8, 24 or 168 hours). You can shorten the duration, not extend it.
  4. The command applies the manifest: a ServiceAccount nexus-<access> in the namespace nexus-access, with its Roles, ClusterRoles and bindings. It creates a token for the chosen duration and checks for about 15 seconds that the API accepts the token and the rights; past that delay it prints a warning and goes on.
  5. The token goes to the keyring and the access file (nexusconfig, the file that nexusctl --nexusconfig <access> reads) is written. No secret is printed.
nexusadm grant request deploy --rule nexus-system:deployments.apps,pods:get,list,patch \
  --duration 2h --holder ci --reason "Roll out version 1.4 of the dashboard"

grant extend: add rights to an access

nexusadm grant extend <access> [--rule ...]... [--port-forward <namespace>]... [--secret <reference>]... [--reason <text>] [--allow-sensitive]

Adds rules and Secret references to an existing, unexpired access. The options have the syntax of grant request. --preset, --duration and --holder exit with code 2: the token, the expiry and the holder stay as they are.

nexusadm grant extend deploy --rule nexus-system:services:get

grant list: list the accesses

nexusadm grant list

Deletes the expired accesses, then prints one line per access: name, holder, expiry (UTC) and number of rules, the preset counting as one rule. No window.

grant show: show an access

nexusadm grant show <access>

Prints the holder, the reason and the expiry of the access, then the manifest applied to the cluster. Exits with code 1 if no access has that name.

nexusadm grant show deploy

grant revoke: delete an access

nexusadm grant revoke <access> | --all

Deletes the ServiceAccount, Roles, ClusterRoles and bindings of the access, its token in the keyring and its access file. --all deletes every access that nexusadm manages, and the objects of the single access used before named accesses existed. No window opens.

nexusadm grant revoke deploy

secret add, show, rm: keyring secrets

nexusadm secret add <name>
nexusadm secret show <name>
nexusadm secret rm <name>

The name has 1 to 40 characters: lowercase letters, digits and hyphens, without a hyphen at either end. The secret is stored in the keyring of your desktop session, through secret-tool.

SubcommandEffect
addOpens a password window. The value never goes through the arguments or the standard output. An empty value counts as a refusal (code 3).
showShows the value in a window, never on the standard output. Exits with code 1 if the secret does not exist.
rmDeletes the secret, without a window.

A keyring secret is used through the reference SECRET:keyring/<name>, in nexusctl ... --from-literal=<key>=SECRET:keyring/<name>, with an access that lists it (--secret keyring/<name>). nexushelm rejects references.

nexusadm secret add registry-password

audit: read the API audit log

nexusadm audit [--since 24h] [--json]
OptionDefaultEffect
--since <d>24hPeriod to read, from 1m to 720h.
--jsonOne JSON object per line, with the fields heure, noeud, compte, verbe, ressource, groupe, sous_ressource, namespace, nom, code and verdict.

The command reads, over SSH, the audit files of the API server in /var/snap/microk8s/common/audit on each node of the inventory. The cluster audit policy records requests on Secrets, reads included, and every modification. The command keeps the requests of the access accounts (nexus-*) and gives each one a verdict:

VerdictMeaning
conformeThe rights of the access cover the request.
hors accèsThe request succeeded but falls outside the rights of the access.
refuséThe API answered 401 or 403.
accès suppriméThe access no longer exists.

The check of the read-only preset is an approximation: it covers every read except Secrets. The command exits with code 1 when a request is hors accès or refusé, or when the log of a node could not be read.

nexusadm audit --since 2h

doctor: check the nodes

nexusadm doctor [--fix]

Checks each node of the inventory over SSH and prints one line per check, ok or ÉCHEC with a detail:

CheckFails when
inventaireThe node has no address in the inventory.
sshThe node cannot be reached.
kubeliteThe service snap.microk8s.daemon-kubelite is not active.
readyzThe /readyz report of the local API is incomplete. Not run on worker nodes.
dqlitedqlite logged “no known leader” or “no route to host” in the last 3 minutes. Not run on worker nodes.
réseauThe node cannot ping another node of the inventory.
kubeletThe kubelet logged “node is not registered yet” in the last minute.
crashkubelite stopped with status=255 3 times or more in 10 minutes.
wifiThe Wi-Fi link uses the 2.4 GHz band or transmits below 200 Mbit/s. Wired nodes are not checked.
ReadyAnother node with a healthy API sees this node as not Ready.
podsA pod has been Pending or terminating for more than 5 minutes.
OptionEffect
--fixRestarts kubelite on the nodes whose kubelite, readyz, kubelet, Ready or pods check fails, after confirmation.

Without --fix, the command exits with code 1 when a node needs a restart of kubelite, cannot be reached, restarts in a loop, or has a degraded Wi-Fi link, and with code 0 otherwise. A failing dqlite or réseau check alone gives code 0. With --fix, the command exits with code 0 once every restarted node is back.

--fix does not restart:

The restart handles one node at a time, nodes with a failing API first. After each restart, the command waits up to 3 minutes for a complete /readyz, a kubelet that sees its node and the Ready state, and stops at the first node that does not come back.

nexusadm doctor --fix

log: read the journal

nexusadm log [-n N] [--json]
OptionDefaultEffect
-n N20Number of commands shown, the most recent ones. N is a positive integer.
--jsonOne JSON object per command, with the fields id, outil, heure, compte, args, decision, code_sortie and duree_ms.

The table shows the local time, the account, the command (cut at 70 characters), the outcome and the duration. The outcome is refusée for a refused or unanswered window, en cours ou interrompue when the command has no end entry, accordée, ok or accordée, code N after a confirmation, and code N otherwise. The journal also holds the commands of nexusctl and nexushelm.

nexusadm log -n 50

Confirmation window

node add, node remove, node reboot, cluster upgrade, grant, grant request, grant extend, secret add, secret show and doctor --fix open a window with zenity on your desktop session. The window shows what the action does, with the buttons Autoriser and Refuser, and closes after 120 seconds.

OutcomeDecision in the journalExit code
Click on AutoriseraccordeeThe code of the action
Click on Refuser, or the window is closedrefusee3
zenity is missing, no display is reachable, or 120 seconds pass without an answerindisponible4

Code 4 means that no decision was taken: run the command again from a desktop session. Two cases differ from this table. For secret show, any ending other than Fermer gives code 4. For grant request, a duration that does not come from the list also gives code 4.

Files and environment variables

FileContent
infra/.nexusctl/journal.jsonl in the repositoryThe journal, shared with nexusctl and nexushelm. One JSON line per event: debut (tool, time, operating system user, account, folder, arguments), decision, secret (references resolved, never their values) and fin (exit code, duration). Created with mode 0600 in a folder with mode 0700. If the start entry cannot be written, the command does not run and exits with code 1.
<name>.json in the access folderThe access file: server address, cluster certificate, access name, holder, expiry, and the Secret references and namespaces that nexusctl and nexushelm use. It holds no token.
Desktop keyringThe token of each access (service nexus grant <access>) and the secrets of nexusadm secret (service nexus secret <name>).
inventory/noeud-<name>.yml in the Ansible folderWritten by node add, deleted by node remove.
VariableDefaultRole
NEXUSCTL_JOURNALinfra/.nexusctl/journal.jsonlPath of the journal.
NEXUS_CONFIG_DIR$XDG_CONFIG_HOME/nexus, else ~/.config/nexusAccess folder.
NEXUS_ADMIN_KUBECONFIGconfig.yaml in the nexus configuration folder (NEXUS_CONFIG_DIR, else $XDG_CONFIG_HOME/nexus, else ~/.config/nexus)Administration kubeconfig, produced by the playbook (tag kubeconfig). Needed by every subcommand that reads or changes the cluster, except node list and node add.
NEXUS_ANSIBLE_DIR~/.config/nexus/ansibleAnsible folder: inventory/, playbooks/site.yml. Required by node add, node remove, node reboot, cluster upgrade, audit and doctor; node list reads it to compare with the cluster.
NEXUSCONFIGreadAccess used by node list.