v3.netdev.be

Architectural Migration: K3s Edge Refactoring with Agent Substrate & Google AX

This document serves as the official blueprint for the “10x” architectural refactoring of the internal Cloud Infrastructure Hub. It details the migration of our edge-deployed K3s control plane to integrate Agent Substrate and Google AX (Agent Executor), achieving massive scalability, strict tenant isolation via gVisor, and zero-loss execution recovery.


1. Executive Summary & Design Goals

At our current operational scale, the lightweight edge-native K3s cluster experiences control-plane congestion during heavy developer onboarding, multiple Crossplane provider bootstrappings, and rapid multi-agent executions.

To overcome these latency and security bottlenecks, we are refactoring our core orchestration architecture around three engineering objectives:

  1. Control-Plane Offloading: Remove ephemeral and high-chatter agent scheduling from the primary K3s API server and etcd database.
  2. Strict Multi-Tenant Isolation: Secure all workspace containers and third-party controllers using user-space kernel sandboxing (gVisor runsc) with sub-millisecond execution multiplexing.
  3. Durable & Resilient Execution: Prevent task corruption and deployment failures in unreliable edge environments through single-writer append-only event logs and automatic state recovery.

2. Platform Architecture Evolution

The refactored system splits responsibilities into three major layers: the Visual Agentic Cockpit (Backstage), the Distributed Execution Control Plane (Google AX), and the High-Density Sandbox Substrate (Agent Substrate).

+-----------------------------------------------------------------------+
|                    1. Visual Agentic Cockpit (Backstage)              |
|        - React Component Plugins  - MCP Client Sessions (SSE/WS)      |
+--------------------------------------------------+--------------------+
                                                   | (MCP Stream)
                                                   v
+--------------------------------------------------+--------------------+
|                2. Distributed Execution Control Plane (Google AX)     |
|   - Single-Writer Log Controller      - Active Lease Manager (etcd)   |
|   - Durability Engine (State Logs)    - Tekton/Crossplane State Sync  |
+--------------------------------------------------+--------------------+
                                                   | (Teleport Session)
                                                   v
+--------------------------------------------------+--------------------+
|               3. High-Density Sandbox Substrate (Agent Substrate)     |
|   - Warm Worker Pod Pool              - Instant Session Teleport      |
|   - gVisor (runsc) Sandbox Boundary   - Local Temp FS Snapshotting    |
+--------------------------------------------------+--------------------+
                                                   | (Reconciliation)
                                                   v
+-----------------------------------------------------------------------+
|                4. Infrastructure Control Plane (Crossplane)           |
|        - Unified Declarative API (KRM)  - Cloud Resource Providers    |
+-----------------------------------------------------------------------+

3. Substrate & Crossplane Integration (Bootstrap & Isolation 10x)

Control-Plane Offloading

Traditional Kubernetes control loops rely heavily on persistent CRD polling and etcd writes, causing etcd write locks and API throttling under high frequency.

High-Density Worker Pod Multiplexing

To maintain a small RAM/CPU footprint on edge hardware (such as Raspberry Pi 5), Substrate does not allocate a dedicated K3s Pod per agent session.

Sandboxing via gVisor (runsc)

Because agents and Crossplane providers execute untrusted code or manage sensitive cloud credentials, they must be rigorously isolated from the host operating system.

State-Transition Fast-Pathing (Instant Session Teleport)

To avoid standard pod cold-starts, Substrate utilizes high-speed memory and filesystem snapshots:


4. Distributed Agent Runtime with Google AX

Durable Execution Engine

Google AX runs as our primary state-transition supervisor, ensuring that long-running developer pipelines (Tekton) and infrastructure operations are fully durable.

sequenceDiagram
    autonumber
    actor Dev as Developer (Backstage UI)
    participant Backstage as Backstage React Plugin
    participant AX as Google AX Controller (Single-Writer)
    participant Substrate as Agent Substrate Scheduler
    participant Worker as Warm Worker Pod (gVisor)
    participant Crossplane as Crossplane Control Plane
    participant Cloud as Cloud Provider (GCP)

    Dev->>Backstage: Click "Provision App Workspace"
    Note over Backstage, AX: Persistent MCP Connection (SSE / WebSockets)
    Backstage->>AX: Invoke MCP Tool: 'CreateWorkspace' (Payload: Composition Config)
    
    rect rgb(240, 248, 255)
        Note over AX: Single-Writer Controller Log
        AX->>AX: Write 'WorkspaceProvision_Started' to Durable Event Log
    end

    AX->>Substrate: Schedule Isolated Actor (Polecat)
    
    rect rgb(230, 245, 230)
        Note over Substrate, Worker: Sub-second Suspend/Resume
        Substrate->>Worker: Teleport In-Memory Snapshot (Instant Session Teleport)
    end

    Note over Worker: gVisor (runsc) Sandbox Boundary
    Worker->>Crossplane: Apply Declarative Manifest (XAgentWorkspace CRD)
    
    Crossplane->>Cloud: Provision Infrastructure (Virtual Machine, Database)
    Cloud-->>Crossplane: Resource Ready Signal

    Crossplane-->>Worker: Update KRM status (Ready)
    
    rect rgb(240, 248, 255)
        Note over AX: Durable State Commit
        Worker->>AX: Commit Trajectory State (Success)
        AX->>AX: Write 'WorkspaceProvision_Completed' to Durable Event Log
    end

    AX-->>Backstage: Stream KRM state transition over MCP
    Backstage-->>Dev: Display active success states & dynamic UI update

5. Backstage Front-End Evolution (The 10x UX)

Our Backstage developer portal undergoes a complete paradigm shift, evolving from a static catalog into an active agentic cockpit.

Decoupling via Model Context Protocol (MCP)

Instead of forcing the Backstage UI to repeatedly query the K3s API server for agent states—which causes API throttling and high CPU overhead—we decouple communications using the Model Context Protocol (MCP):


6. Implementation & Migration Phases

Phase 1: Infrastructure Foundations (Complete)

Phase 2: Agent Substrate Configuration

Phase 3: Google AX Controller Setup

Phase 4: Backstage Evolution