← Back to Pull requests

Environment: Add provider-neutral Kubernetes environment with pod-native Compose and BuildKit #2819

Closed
unknown closed this pull request without merging on Oct 28, 2026 13:51 UTC
View on GitHub
unknown unknown commented on Aug 21, 2026 09:35 UTC
Author

Summary


This PR adds a provider-neutral Kubernetes execution stack to Harbor:
- extracts shared Kubernetes primitives from the existing GKE environment
- adds a generic kubernetes environment for any cluster reachable through kubeconfig or an in-cluster service account
- supports Docker Compose through either DinD or native Kubernetes sidecars
- adds optional Docker and BuildKit image-builder backends
- supports pull-through and prepopulated OCI mirrors for prebuilt images
- preserves existing GKE behavior while sharing its hardened Kubernetes implementation
## Motivation
Harbor's existing Kubernetes implementation is coupled to GKE even though most
pod lifecycle, execution, transfer, cleanup, and Compose behavior is not
Google-specific.
The generic environment makes this functionality available to RKE2, k3s,
kubeadm, EKS, AKS, ACK, GKE, kind, minikube, and other conformant Kubernetes
clusters without requiring a cloud-specific CLI.
## Configuration
A complete configuration can look like this:
  environment:
    type: kubernetes
    kwargs:
      namespace: harbor
      context: my-cluster-context

      compose_strategy: pods

      image_mode: auto
      image_registry: registry.example.com/harbor-builds
      image_pull_secret: regcred

      image_builder: buildkit
      buildkit_address: unix:///run/user/1000/buildkit/buildkitd.sock

      prebuilt_image_mirrors:
        docker.io: http://mirror.internal:5000/
      prebuilt_image_mirror_failure_policy: fallback

      node_selector:
        kubernetes.io/arch: amd64

Authentication is resolved from KUBECONFIG, ~/.kube/config, or an in-cluster
service account.
## Kubernetes environment
The new environment supports:
- namespace and kubeconfig context selection
- node selectors, tolerations, labels, and service accounts
- configurable resource requests and limits
- image pull policies and pull secrets
- prebuilt images and Dockerfile-based tasks
- insecure or authenticated registries
- Kubernetes-safe pod names and labels
- command execution, file transfer, artifact collection, and cleanup

Shared Kubernetes behavior now lives in
BaseKubernetesEnvironment. GKE retains only its Google-specific
authentication, image-building, and accelerator behavior.
The shared implementation also preserves exec-stream keepalives, missing-status
detection, collision-resistant resource names, and service-account token
isolation.
## Compose strategies
The generic Kubernetes environment supports two Compose strategies.
### dind
dind is the default and runs Docker Compose inside a privileged
Docker-in-Docker pod. It provides the widest Compose compatibility and supports
network isolation.
### pods
pods translates supported Compose services into native sidecars in a single
ordinary Kubernetes pod.
It preserves:
- service_started and service_healthy dependency ordering
- executable health checks through startup probes
- shared Compose volumes
- service-specific execution and file transfer
- prebuilt and locally built service images
- sidecar artifact collection
- deterministic startup and cleanup

Native sidecars require Kubernetes 1.29 or newer; Kubernetes 1.33 or newer is
recommended.

Because all containers share one pod network namespace, pod-native mode cannot
enforce no-network. One-shot services and unsupported Compose features such as
privileged, ports, devices, and network_mode are rejected before images
are built. DinD remains available for those workloads.
## Image builders
Host-side image construction supports four modes:
- auto: use explicitly configured BuildKit, otherwise a working Docker daemon
- buildkit: require BuildKit without falling back
- docker: require Docker
- none: permit prebuilt-only tasks and reject requested builds

BuildKit is operator-provided. Harbor does not install or launch it; buildctl
and a reachable daemon must already be available through buildkit_address or
BUILDKIT_HOST.

Pod-native Compose rendering still requires the Docker CLI and Compose plugin
for docker compose config, but it does not require a Docker daemon when using
BuildKit or only prebuilt services.
### Build registry requirement
image_registry is required whenever Docker or BuildKit builds an image. It
must be an OCI-compatible registry implementing the Docker Registry HTTP API V2.
The registry must be reachable from:
- the Harbor host or BuildKit daemon, which pushes the built image
- the Kubernetes nodes, whose kubelets pull the image into the workload pod

A BuildKit daemon performs the build but cannot make its local result visible
to Kubernetes. Harbor exports the result with type=image,...,push=true and
places the resulting registry reference in the pod specification.

Prebuilt-only single-container tasks and prebuilt-only pod-native Compose graphs
require neither an image builder nor image_registry.

For private registries, builder pushes use the host's DOCKER_CONFIG, while
kubelet pulls use image_pull_secret. registry_insecure: true is required only
for plain HTTP or untrusted TLS.

## Prebuilt image mirrors
prebuilt_image_mirrors maps source registries to path-preserving pull-through
or prepopulated OCI registries.
For example:
  ubuntu:24.04
  → mirror.internal:5000/library/ubuntu:24.04
  

Harbor probes the mirrored manifest to trigger pull-through population and uses
the mirrored reference when it becomes available. Resolution applies to both
single-container tasks and prebuilt pod-native Compose services, independently
of image_mode.
Mirror failure behavior is configurable:
- fallback: warn and use the original source image
- error: fail before creating the workload pod

Harbor does not configure the mirror itself. Authenticated manifest probes use
the host's DOCKER_CONFIG; Kubernetes runtime pulls continue to use
image_pull_secret. Mirror can be pull-through cache like Zot's sync feature,
or just simple prepopulated registry.

This feature is really useful because it can be used to move images closer to the
harbor runner while also avoiding online registries rate limiting.

## Validation
### Automated checks
- 461 focused Kubernetes and environment tests passed
- Ruff linting passed
- Ruff formatting passed
- type checking passed for every modified environment module
- all 36 patches are equivalent to the reviewed fork stack

### Runtime environment validation
Runtime validation used the Oracle agent on an RKE2 Kubernetes v1.36.1 cluster.
| Dataset | Configuration | Result |
| --- | --- | --- |
| terminal-bench 2.1 | Generic Kubernetes before BuildKit | 87/89 reward-1, no environment exceptions |
| tau3-bench | DinD Compose | 375/375, zero exceptions |
| tau3-bench | Pod-native Compose | 375/375, zero exceptions |
| tau3-bench | BuildKit, pod-native Compose, and pull-through mirror | 375/375, zero exceptions |
| terminal-bench 2.1 | BuildKit and pull-through mirror | 87/89 |

Two terminal-bench zero-reward tasks are known task defects also reproducible
with Docker.
Exact commands and additional validation details are included in the incremental
fork PRs below.

## Review guide
This PR is a linear five-part stack. These fork PRs provide smaller incremental
diffs for review:
1. Extract shared Kubernetes primitives from GKE
2. Add the provider-neutral Kubernetes environment
3. Add pod-native Compose support
4. Add the optional BuildKit backend
5. Add prebuilt image mirror support

Please leave review comments and approvals on this upstream PR. The linked fork
PRs are intended as smaller, incremental diff views.

Closes #1896
<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/harbor-framework/harbor/pull/2819" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open in Devin Review">
</picture>
</a>
<!-- devin-review-badge-end -->

Diff: 650 lines (+487 / -163) across 8 files Reviewer: KunWuLuan Review duration: 98175m
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
0.75
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.289
Sensitive Paths sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #2819"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 75.2% (HIGH) · Higher = larger blast radius
75.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 29.7% · Safe to merge
29.7%