Dual-StorageMode Kubernetes Provisioning (Block + Filesystem), Pod Readiness Polling, and Live Gateway-to-Pod Routing
此内容尚不支持你的语言。
Source:
docs/enhancements/0011-k8s-dual-storage-and-live-pod-routing/README.md· Status:implemented· Area:core· Milestone:v0.3.0
- CEP Number:
0011 - Status:
implementable - Target Version:
v0.3.0 - Components:
pkg/controller/{manifests.go,kubeclient.go,reconciler.go},pkg/gateway/server.go,cmd/cubepod-gateway/main.go,crates/podd-init/src/main.rs
1. Summary
Section titled “1. Summary”To run CubePod across both bare-metal Kata + SPDK Raw Block clusters (volumeMode: Block) and standard Kubernetes test/staging clusters backed by Filesystem CSI drivers such as nfs-storage (volumeMode: Filesystem, runc/containerd), this CEP introduces:
- Configurable
VolumeMode(Blockvs.Filesystem) andRuntimeClassNameinpkg/controller/manifests.goandReconciler. - In-Guest
podd-initLoopback/Filesystem Adaptation: When running onvolumeMode: Filesystemwhere/workspaceis already mounted by kubelet andCAP_SYS_ADMINpivot is skipped or unprivileged (CUBEPOD_SKIP_PIVOT=1or non-block mode),podd-initcleanly prepares/workspaceand/rootfs-upperandexecvps/opt/cubepod/bin/podd. - Real Kubernetes API Authentication & Pod Readiness Polling (
RESTKubeClient): Supports kubeconfig/in-cluster ServiceAccount tokens, optional TLSInsecureSkipVerify, and pollingGET /api/v1/namespaces/{ns}/pods/{name}untilstatus.phase == "Running"andstatus.podIP != ""(with fallback/timeout). - Live Gateway-to-Pod Routing: When
reconciler.Reconcilereturns a non-emptystatus.PodIP(excluding the mock10.244.0.42unless live routing is enabled),cubepod-gatewayautomatically pollsGET http://<podIP>:49983/healthand registersrec.PoddURL = "http://" + status.PodIP + ":49983".
2. Motivation
Section titled “2. Motivation”- Allow CubePod to deploy and run real sandbox Pods on the
192.168.1.207:6443Kubernetes cluster (StorageClass: nfs-storage,volumeMode: Filesystem, containerd runtime) without sacrificingvolumeMode: Block+kata-qemusupport. - Automatically wire
cubepod-gatewayto the scheduled Kubernetes Pod IP (<podIP>:49983) on sandbox creation and Auto-Resume (connect/ data-plane wake-up). - Support
DeleteBoxonReconcilersoDELETE /sandboxes/{id}deletes the underlying Kubernetes Pod (and optionally PVCs whendeleteVolumes=true).
Non-Goals
Section titled “Non-Goals”- Modifying the external E2B wire format.
3. Proposal & Design Details
Section titled “3. Proposal & Design Details”3.1 pkg/controller/manifests.go & pkg/controller/reconciler.go
Section titled “3.1 pkg/controller/manifests.go & pkg/controller/reconciler.go”- Add
VolumeMode("Block"or"Filesystem", default"Block") toBlockPVCManifestandReconcileroptions (WithVolumeMode(mode string),WithDefaultStorageClass(sc string),WithDefaultRuntimeClass(rc string),WithPoddInjectorImage(img string),WithDefaultSandboxImage(img string)). - When
VolumeMode == "Filesystem":BuildBlockPVCssetsVolumeMode: "Filesystem"on bothrootfs-pvcandworkspace-pvc(and omits CSIDataSourceifForkFromis used on a Filesystem StorageClass that lacks VolumeSnapshot/clone support, instead allowing Gateway/Controller data copy).BuildKataPodmountsrootfs-pvcat/mnt/cubepod/rootfsandworkspace-pvcat/workspaceviaVolumeMountsinstead ofVolumeDevices, and setsCUBEPOD_SKIP_PIVOT=1in the container env ifRuntimeClassName == ""(standard unprivileged container runtime).
- Add
DeleteBox(ctx context.Context, name string, deleteVolumes bool) errortoReconcilerso terminating a sandbox deletes its Pod (and PVCs ifdeleteVolumes == true) viaKubeClient.
3.2 pkg/controller/kubeclient.go
Section titled “3.2 pkg/controller/kubeclient.go”- Add
NewRESTKubeClientFromEnv()/RESTKubeClientOptionssupporting:APIServerURL,Namespace,BearerToken,InsecureTLS(tls.Config{InsecureSkipVerify: true}).- Automatic loading from
KUBECONFIG(~/.kube/configclient-certificate-data / client-key-data or token) or in-cluster/var/run/secrets/kubernetes.io/serviceaccount/token!
- In
RESTKubeClient.EnsurePod(ctx, pod):- When
WaitForRunningis enabled onRESTKubeClient, after creating/getting the Pod, pollGET /api/v1/namespaces/{ns}/pods/{name}every 500ms (up to context deadline / 60s) untilstatus.phase == "Running"andstatus.podIP != "".
- When
3.3 pkg/gateway/server.go & cmd/cubepod-gateway/main.go
Section titled “3.3 pkg/gateway/server.go & cmd/cubepod-gateway/main.go”- Add
SetLivePodRouting(enabled bool)ongateway.Server. WhenlivePodRoutingis true andstatus.PodIP != "",ensureRunningandhandleCreateSandboxsetrec.PoddURL = fmt.Sprintf("http://%s:%d", status.PodIP, rec.EnvdPort)and wait up to 30s forGET <PoddURL>/healthto return200 OK. - In
handlePanelProxy/handleCreateEndpoint, whenrec.PoddURL != ""and no explicittargetUrloverride was passed, default the panel upstream tofmt.Sprintf("http://%s:%d", status.PodIP, port)so/panel/{token}/reverse-proxies directly into the Kubernetes Pod’s<port>! - Update
cmd/cubepod-gateway/main.goto accept controller flags (--kube-api,--kubeconfig,--namespace,--storage-class,--volume-mode,--runtime-class,--podd-injector-image,--default-sandbox-image,--live-pod-routing).
4. Test Plan
Section titled “4. Test Plan”- Unit tests in
pkg/controller/kubeclient_test.goverifyingVolumeMode: "Filesystem"Pod/PVC generation,DeleteBox, kubeconfig client-cert/token parsing, andEnsurePodreadiness polling. - Unit tests in
pkg/gateway/server_test.goverifying automaticPoddURLbinding and panel upstream resolution fromPodIP.
5. Graduation Criteria & PRR
Section titled “5. Graduation Criteria & PRR”- Zero breaking changes to existing
Blockmode tests. - Clean fallback when running in-memory without a Kubernetes cluster.
6. Alternatives Considered
Section titled “6. Alternatives Considered”- Require
volumeMode: Blockon all clusters: Rejected because many developer and staging Kubernetes clusters use NFS (nfs-storage) orlocal-pathprovisioners that only supportvolumeMode: Filesystem.