my-homelab-configs/bootstrap/platform
juvenal.diaz a9a4f72e40
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details
Isolate node exporter listener from host networking
2026-11-02 16:17:28 -06:00
..
grafana-dashboards Add OCI VM alarms and unified observability dashboard 2026-10-28 22:44:28 -06:00
.terraform.lock.hcl redesign 2026-05-23 21:00:28 -06:00
README.md Isolate Kubernetes profile state and pin cluster identities before mutations 2026-10-30 22:19:28 -06:00
main.tf Isolate node exporter listener from host networking 2026-11-02 16:17:28 -06:00
variables.tf Pin Tetragon for k3s CRD compatibility 2026-11-02 15:49:59 -06:00

README.md

Platform components

Kubernetes stacks use pinned cluster identities and profile-specific state. Enroll the intended cluster and review legacy state migration before the first deployment with this guard. Identity mismatches never trigger automatic adoption.

The platform stack keeps one OpenTofu state file, but Jeannie exposes isolated component applies. A component apply passes only that component's resource addresses as -target arguments; OpenTofu includes required dependencies and does not apply unrelated platform resources.

Run these on the Debian homelab host with the active cluster profile:

LAB_CLUSTER_PROFILE=pimox ./jeannie platform monitoring
LAB_CLUSTER_PROFILE=pimox ./jeannie platform calico
LAB_CLUSTER_PROFILE=pimox ./jeannie platform logging
LAB_CLUSTER_PROFILE=pimox ./jeannie platform argocd
LAB_CLUSTER_PROFILE=pimox ./jeannie platform all

Available components are calico, metrics, dns, metallb, ingress, storage, argocd, security, logging, monitoring, and tools.

Targeted applies skip the legacy platform-wide adoption pass. The monitoring target performs its own scoped adoption after OpenTofu initialization: existing Helm releases (prometheus-stack and Mimir when enabled), the monitoring namespace, scheduling priority, and repo-managed dashboard ConfigMaps are imported only when missing from state. It checks the selected control-plane node before adoption, preserves existing state entries, and stops on discovery errors rather than treating them as absent resources. No release uninstall or PVC deletion is involved. Use platform all for platform-wide adoption.

The Calico target similarly adopts the existing calico-crds and calico Helm releases in the configured Calico namespace, without uninstalling either release or deleting CRDs. It verifies the selected control plane and the desired operator node exist before changing state or applying the rollout. A stale debian selector in the Pimox profile therefore produces a placement error instead of creating another unschedulable operator pod.

Scoped platform imports retry recognized Kubernetes transport failures (including TLS bad-record-MAC responses) up to three times, with five seconds between attempts. Each attempt rereads state so an import already recorded by a prior attempt is not repeated. Authentication, authorization, configuration, and other errors fail immediately. LAB_TOFU_K8S_IMPORT_RETRIES overrides the attempt limit; certificate verification stays enabled throughout.

The Argo CD target also adopts an existing argocd Helm release in its configured namespace when missing from state, after checking the selected control plane. It preserves release metadata and does not uninstall the release.

ApplicationSet and the Argo CD server each request 25m CPU, retaining their 300m limits and existing memory settings. Compared with their previous 100m requests, this frees 150m on a worker hosting both pods, enough for Tetragon's 125m request in the observed one-core worker layout. This is a small homelab baseline, not a guarantee against CPU contention during bursts. Their rolling updates use zero surge and permit one unavailable replica so a full worker can release the old reservation before admitting its replacement. A single-replica Argo CD UI or ApplicationSet controller may be briefly unavailable during its update. Apply with LAB_CLUSTER_PROFILE=pimox ./jeannie platform argocd; the readiness step waits for the Argo CD rollouts. This does not change worker CPU topology.

Scheduling feasibility before deployment

Every platform and application OpenTofu apply now runs scripts/scheduling-preflight.py first, including retry attempts. The pipeline creates a private temporary plan, renders the selected Helm releases using their planned values and chart versions, and reads the selected cluster's nodes, active Pods, controllers, PVCs, PVs, StorageClasses, and namespace labels. It also renders local Kustomize/plain-manifest Argo CD sources for application applies. The temporary plan and chart values are removed when the check finishes.

The check uses allocatable capacity minus requests, not kubectl top usage or an arbitrary minimum core count. Worker-01 can stay at one CPU. The former LAB_PIMOX_APP_DEPLOY_MIN_CPUS setting no longer gates application deployment; the early worker check verifies readiness, and the scheduling estimate checks the actual requested workloads before apply.

The estimate accounts for CPU, memory, Pod slots, other requested resources, init containers and restartable sidecars, explicit Pod overhead, selectors, required node/Pod affinity, taints/tolerations, hard topology spread, host ports, bound PV node affinity, and single-writer PVC placement. Rolling deployments must have room for their surge unless their strategy permits replacing an old Pod first. Existing Pods' reservations remain charged until the simulated rollout allows removal; terminating Pods do not silently free capacity.

An unschedulable workload reports its per-node blockers and stops deployment. Discovery, rendering, unknown planned chart values, and unsupported hard constraints also stop the apply. This check does not change workloads, remove Pods, resize VMs, alter requests, or attempt preemption. The existing state adoption step still runs before the check to make the plan possible.

This is a conservative, sequential placement estimate, not kube-scheduler or an admission dry run. It tries resource reductions first and can reject a layout that a different rollout/placement order would admit. Preferred placement is not a hard constraint. Admission-added sidecars/defaults, concurrent cluster changes, provisioning capacity, CSI attachment limits, quotas, hook Jobs, and future autoscaling are not proven by it. Local GitOps rendering assumes the checkout matches the revision Argo CD will deploy. The check verifies that the Application repository matches a local remote and its locally resolved revision matches HEAD; it does not fetch the remote branch. Only image overrides are supported. Unsupported Application renderers and unpinned chart identities fail rather than silently assuming an empty workload.

Prometheus and Alertmanager upgrades reuse the live Operator-generated Pod templates for sidecars and PVCs while overlaying planned resources/placement. A missing Operator template blocks this estimate; first-time Operator workload bootstrap needs a separately reviewed path. Other Operator-generated workloads (for example Calico's Installation) are explicitly reported as outside the rendered workload check. Dynamic PVC provisioning gets a notice, not a claim that storage capacity exists. Live post-apply readiness checks remain required. The actual apply replans after this check; its result is a snapshot, not a reservation or a guarantee against races.

Run a focused deployment as usual on Debian:

LAB_CLUSTER_PROFILE=pimox ./jeannie platform argocd

Regression cases are provided for execution on Debian; they are not run on the development laptop:

python3 -m unittest discover -s tests/jeannie -p 'test_scheduling_preflight.py'

Monitoring during reduced CPU capacity

platform monitoring creates the homelab-monitoring PriorityClass before updating Prometheus, Grafana, and their Operator. These workloads have priority 100000, above ordinary workloads and below Kubernetes system-critical pods. If their local-volume node has no unreserved CPU, the scheduler can preempt lower-priority pods to admit monitoring. Those workloads may remain Pending until capacity is restored; priority does not add CPU capacity.

Prometheus requests 25m CPU plus 25m for its config reloader. It can run on a one-core VM when that scheduling budget is available. Existing node selectors, PVCs, and PV node affinity are retained: the pipeline does not move hostpath data, delete claims, or schedule monitoring on the control plane to bypass storage placement.

Readiness checks follow Deployments, StatefulSets, and DaemonSets, including the StatefulSets generated by Prometheus Operator (whose instance label can differ from the Helm release). Old failed pods do not block a healthy replacement. Missing Prometheus or Grafana workloads, incomplete rollouts, and unavailable replicas still fail the check. The pipeline runs a live check even on an unchanged apply, and prints scheduling events, requests, and volume placement when the bounded readiness wait fails.

The pipeline also recovers Grafana's OrderedReady update deadlock: if its sole pod is Pending and unscheduled on an old controller revision without the new monitoring priority, readiness replaces that pod so the StatefulSet can create the desired revision. Eligibility requires matching controller ownership, an observed unpartitioned RollingUpdate, and the homelab-monitoring target priority. The delete uses UID and resource-version preconditions; a replacement or newly scheduled pod is preserved. Running, assigned, terminating, and current-revision pods are never recycled, and PVCs are not deleted. Calling scripts/monitoring-readiness.py directly remains read-only unless --recover-stale-pending is explicitly supplied; the deployment pipeline supplies that flag automatically.

After syncing the repository, run on Debian or through the remote API:

./jeannie remote platform monitoring

The monitoring target includes the scheduling priority dependency and the repo-managed dashboard ConfigMaps; no separate pod deletion or dashboard restart command is required.